﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using AreaEdit.ModifiedAreat;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Gpc;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;
using YJKArchKernel.OutWallSearch;
using YJKArchMethodLibrary.Utils;
using YJKCodeBase.TopologySuite;
using YRevitJig;
using YJKRevitCode.RevitTopologySuite;
using YJKRevitCode.RevitTopologySuite.GPCAdapter;

namespace AreaEdit.AreaSet
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	public class AreaCreator
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public AreaCreator(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
			this.m_doc = cmdData.Application.ActiveUIDocument.Document;
			this.m_sel = cmdData.Application.ActiveUIDocument.Selection;
			this.m_uiDoc = cmdData.Application.ActiveUIDocument;
		}

		public bool CreateInsideArea(Autodesk.Revit.DB.Document doc, List<Room> rooms, InsideAreaLableInfo labelInfo, string RangeType, List<Wall> lstAllOutWall)
		{
			List<CurveInformationBean> roomCurveBeansWithoutInstance = AreaCreator.GetRoomCurveBeansWithoutInstance(doc, rooms);
			List<CurveInformationBean> list = AreaCreator.BreakCurves(roomCurveBeansWithoutInstance);
			AreaCreator.RemoveRepeatCurves(list);
			List<RichPoint> list2 = AreaCreator.ConstructRichPointSet(list);
			AreaCreator.DeleteSingleEdgePoint(ref list2);
			list2.Sort(new RichPointComparer());
			List<List<CurveInformationBean>> longestPathBeanAreas = this.GetLongestPathBeanAreas(list2);
			OffsetWallLine offsetWallLine = new OffsetWallLine(this.m_Revit, "CenterLine");
			List<List<Curve>> curveAryForInsideArea = offsetWallLine.GetCurveAryForInsideArea(longestPathBeanAreas, rooms, lstAllOutWall, RangeType);
			Transaction transaction = new Transaction(doc, "CreateInsideArea");
			transaction.Start();
			foreach (List<Curve> list3 in curveAryForInsideArea)
			{
				Area area = Common.CreateArea(doc, list3);
				this.AddSharedParaToArea(doc, area, rooms[0]);
				doc.Regenerate();
				XYZ areaCurveCenterPt = offsetWallLine.GetAreaCurveCenterPt(list3);
				this.AddAreaTag(doc, areaCurveCenterPt, area, labelInfo);
				List<ElementId> roomsInArea = this.GetRoomsInArea(list3, rooms);
				string suiteName = rooms[0].GetParameter("户型名称").AsString().Trim();
				string hoomNumb = rooms[0].GetParameter("户型编号").AsString().Trim();
				AreaInfoManager.WriteExtensibleStorageToArea(area, AreaType.AT_Suite, suiteName, hoomNumb, roomsInArea);
			}
			transaction.Commit();
			return true;
		}

		public bool RefreshFireZoneStyle(Autodesk.Revit.DB.Document doc, FireZoneLableInfo labelInfo, LinePatternElement linePattern)
		{
			List<ClosedArea> fireZoneBoundary = this.GetFireZoneBoundary(doc);
			List<ElementId> list = new List<ElementId>();
			List<Area> list2 = Common.FilterFireAreas(doc);
			if (list2.Count > 0)
			{
				foreach (Area area in list2)
				{
					Common.DeleteArea(doc, area.Id);
				}
			}
			Transaction transaction = new Transaction(doc, "CreateFireZone");
			transaction.Start();
			List<AreaTag> list3 = Common.FilterAreaTags(doc);
			if (list3.Count > 0)
			{
				foreach (AreaTag areaTag in list3)
				{
					doc.Delete(areaTag.Id);
				}
			}
			transaction.Commit();
			foreach (ClosedArea closedArea in fireZoneBoundary)
			{
				Area area2 = Common.CreateArea(doc, closedArea, labelInfo, linePattern, ref list);
				Transaction transaction2 = new Transaction(doc, "Create FireZoneTag");
				transaction2.Start();
				this.SetFireZoneParameters(doc, area2, closedArea.m_fireZoneInfo);
				doc.Regenerate();
				XYZ ptCenter = null;
				this.SetFireZoneTag(doc, ptCenter, area2, closedArea.m_fireZoneInfo, labelInfo);
				transaction2.Commit();
			}
			return true;
		}

		public bool CreateFireZoneByManualDraw(Autodesk.Revit.DB.Document doc, FireZoneForm dlg, LinePatternElement linePattern)
		{
			DrawFireZoneForm drawFireZoneForm = new DrawFireZoneForm();
            drawFireZoneForm.Location = new System.Drawing.Point(dlg.Location.X + dlg.Width, dlg.Location.Y);
			drawFireZoneForm.Show(dlg);
			int wMsg = 7;
			AreaCreator.SendMessage(CmdFireZone._hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			List<ElementId> list = new List<ElementId>();
			XYZ xyz = XYZ.Zero;
			bool flag = true;
			TransactionGroup transactionGroup = null;
			bool flag2 = true;
			for (;;)
			{
				if (flag2)
				{
					transactionGroup = new TransactionGroup(doc, "TransactionGroup");
				}
				try
				{
					if (flag2)
					{
						transactionGroup.Start();
						flag2 = false;
					}
					FireZoneLableInfo labelInfo = dlg.m_labelInfo;
					GraphicsStyle lineStyle = Common.ModifyLineStyle(doc, "AreaBoundaryLine", labelInfo.m_lineWidth, labelInfo.m_lineColor);
					if (drawFireZoneForm.m_eDrawMode == DrawMode.Line)
					{
						if (flag)
						{
							xyz = this.m_sel.PickPoint("请输入起点");
						}
						XYZ xyz2 = RevitExtensionAPI.PickOtherPoint(xyz, this.m_uiDoc, "请输入直线终点");
						Line curve = Line.CreateBound(xyz, xyz2);
						DetailCurve detailCurve = this.CreateDetailCurve(doc, curve, lineStyle, linePattern);
						list.Add(detailCurve.Id);
						xyz = xyz2;
						flag = !drawFireZoneForm.Chain;
					}
					else if (DrawMode.Rect == drawFireZoneForm.m_eDrawMode)
					{
						xyz = this.m_sel.PickPoint("请输入矩形的起点");
						XYZ pt = RevitExtensionAPI.PickRectOtherPoint(xyz, this.m_uiDoc, "请输入矩形的对角点");
						List<Line> list2 = Common.CreateRect(xyz, pt);
						foreach (Line curve2 in list2)
						{
							DetailCurve detailCurve2 = this.CreateDetailCurve(doc, curve2, lineStyle, linePattern);
							list.Add(detailCurve2.Id);
						}
						flag = true;
					}
					else if (DrawMode.Arc3Pt == drawFireZoneForm.m_eDrawMode)
					{
						if (flag)
						{
							xyz = this.m_sel.PickPoint("请输入弧线起点");
						}
						XYZ xyz3 = RevitExtensionAPI.PickOtherPoint(xyz, this.m_uiDoc, "请输入弧线终点");
						XYZ xyz4 = RevitExtensionAPI.PickArcMidPoint(xyz, xyz3, this.m_uiDoc, "请输入弧线上一点");
						Arc curve3 = Arc.Create(xyz, xyz3, xyz4);
						DetailCurve detailCurve3 = this.CreateDetailCurve(doc, curve3, lineStyle, linePattern);
						list.Add(detailCurve3.Id);
						xyz = xyz3;
						flag = !drawFireZoneForm.Chain;
					}
					else if (DrawMode.ArcCenter == drawFireZoneForm.m_eDrawMode)
					{
						xyz = this.m_sel.PickPoint("请输入圆心");
						XYZ xyz5 = this.m_sel.PickPoint("请输入弧线起点");
						XYZ ptArcEnd = RevitExtensionAPI.PickArcEndPoint(xyz5, xyz, this.m_uiDoc, "请输入弧线终点");
						Arc curve4 = Common.CreateArc(xyz, xyz5, ptArcEnd);
						DetailCurve detailCurve4 = this.CreateDetailCurve(doc, curve4, lineStyle, linePattern);
						list.Add(detailCurve4.Id);
						flag = true;
					}
					else
					{
						if (DrawMode.Delete == drawFireZoneForm.m_eDrawMode)
						{
							DetailCurveFilter detailCurveFilter = new DetailCurveFilter();
							IList<Element> list3 = this.m_sel.PickElementsByRectangle(detailCurveFilter, "请框选需要删除的面积边线");
							Transaction transaction = new Transaction(doc, "DeleteElements");
							transaction.Start();
							foreach (Element element in list3)
							{
								list.Remove(element.Id);
								doc.Delete(element.Id);
							}
							transaction.Commit();
							flag = true;
							continue;
						}
						if (DrawMode.Finish == drawFireZoneForm.m_eDrawMode)
						{
							List<Curve> list4 = new List<Curve>();
							foreach (ElementId elementId in list)
							{
								DetailCurve detailCurve5 = doc.GetElement(elementId) as DetailCurve;
								list4.Add(detailCurve5.GeometryCurve);
							}
							bool flag3 = true;
							List<RichPoint> list5 = AreaCreator.ConstructRichPointSet(list4);
							List<XYZ> list6 = new List<XYZ>();
							foreach (RichPoint richPoint in list5)
							{
								if (richPoint.m_curves.Count < 2)
								{
									flag3 = false;
									list6.Add(richPoint.m_point);
								}
							}
							if (!flag3)
							{
								if (2 != list6.Count || list6[0].DistanceTo(list6[1]) >= 2.0)
								{
									YJKMessageBox.Show("区域不闭合。");
									drawFireZoneForm.m_eDrawMode = drawFireZoneForm.GetChecked();
									continue;
								}
								list4.Add(Line.CreateBound(list6[0], list6[1]));
								list5 = AreaCreator.ConstructRichPointSet(list4);
							}
							list5.Sort(new RichPointComparer());
							List<ClosedArea> closedAreas = this.GetClosedAreas(list5);
							List<ClosedArea> fireZoneBoundary = this.GetFireZoneBoundary(doc);
							List<ClosedArea> list7 = this.RegroupAreas(closedAreas, fireZoneBoundary);
							Transaction transaction2 = new Transaction(doc, "CreateFireZone");
							transaction2.Start();
							doc.Delete(list);
							transaction2.Commit();
							foreach (ClosedArea closedArea in closedAreas)
							{
								if (ElementId.InvalidElementId != closedArea.m_areaId)
								{
									this.CreateFireZone(doc, closedArea, dlg.m_fireZoneInfo, dlg.m_labelInfo, linePattern, false);
								}
							}
							foreach (ClosedArea closedArea2 in list7)
							{
								this.CreateFireZone(doc, closedArea2, dlg.m_fireZoneInfo, dlg.m_labelInfo, linePattern, true);
							}
							transactionGroup.Assimilate();
							dlg.SetTbNumber();
							flag2 = true;
							drawFireZoneForm.m_eDrawMode = drawFireZoneForm.GetChecked();
							list = new List<ElementId>();
							flag = true;
							continue;
						}
					}
					if (this.IsClosed(doc, list))
					{
						flag = true;
					}
					continue;
				}
				catch (Autodesk.Revit.Exceptions.OperationCanceledException)
				{
					if (dlg.m_clickMode)
					{
						dlg.m_clickMode = false;
						transactionGroup.RollBack();
						drawFireZoneForm.Close();
						return false;
					}
					if (dlg.m_clickSetOk)
					{
						dlg.m_clickSetOk = false;
						if (dlg.m_refreshExist)
						{
							transactionGroup.RollBack();
							drawFireZoneForm.Close();
							this.RefreshFireZoneStyle(doc, dlg.m_labelInfo, linePattern);
							return false;
						}
						continue;
					}
					else
					{
						if (drawFireZoneForm.m_clickMode)
						{
							drawFireZoneForm.m_clickMode = false;
							continue;
						}
						transactionGroup.RollBack();
						drawFireZoneForm.Close();
						return true;
					}
				}
				catch (Exception ex)
				{
					YJKMessageBox.Show(ex.Message);
					transactionGroup.RollBack();
				}
				break;
			}
			return true;
		}

		public bool CreateFireZoneByRooms(Autodesk.Revit.DB.Document doc, List<Room> rooms, FireZoneInfo fireZoneInfo, FireZoneLableInfo labelInfo, LinePatternElement linePattern, List<WallData> lstAllOutWall)
		{
			OffsetWallLine offsetWallLine = new OffsetWallLine(this.m_Revit, "CenterLine");
			List<Curve> outerBoundary = new List<Curve>();
			List<CurveInformationBean> roomCurveBeansWithoutInstance = AreaCreator.GetRoomCurveBeansWithoutInstance(doc, rooms);
			if (!AreaCreator.AdjustCurvesWithErrorInfo(ref roomCurveBeansWithoutInstance, doc))
			{
				return false;
			}
			List<List<CurveInformationBean>> largestClosedAreas = this.GetLargestClosedAreas(roomCurveBeansWithoutInstance);
			List<List<CurveInformationBean>> innerAreaBeans = this.GetInnerAreaBeans(doc);
			List<ClosedAreaMoreInformation> allAreas = this.GetAllAreas(largestClosedAreas, innerAreaBeans);
			List<ClosedArea> fireZoneBoundary = this.GetFireZoneBoundary(doc);
			foreach (ClosedAreaMoreInformation closedAreaMoreInformation in allAreas)
			{
				outerBoundary = offsetWallLine.GetCurveAryForFireZoneArea(closedAreaMoreInformation, rooms, lstAllOutWall);
				closedAreaMoreInformation.m_outerBoundary = outerBoundary;
			}
			List<ClosedArea> list = this.RegroupAreas(allAreas.Cast<ClosedArea>().ToList<ClosedArea>(), fireZoneBoundary);
			foreach (ClosedArea closedArea in allAreas)
			{
				if (ElementId.InvalidElementId != closedArea.m_areaId)
				{
					this.CreateFireZone(doc, closedArea, fireZoneInfo, labelInfo, linePattern, false);
				}
			}
			foreach (ClosedArea closedArea2 in list)
			{
				this.CreateFireZone(doc, closedArea2, fireZoneInfo, labelInfo, linePattern, true);
			}
			return true;
		}

		public static List<Curve> GetRoomCurvesWithoutInstance(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			List<Curve> list = new List<Curve>();
			foreach (Room room in rooms)
			{
				List<Curve> wallCurves = AreaCreator.GetWallCurves(room, doc);
				List<Curve> closedAreaCurves = AreaCreator.GetClosedAreaCurves(wallCurves);
				List<Curve> list2 = AreaCreator.BreakCurves(closedAreaCurves);
				AreaCreator.RemoveRepeatCurves(list2);
				List<RichPoint> list3 = AreaCreator.ConstructRichPointSet(list2);
				AreaCreator.DeleteSingleEdgePoint(ref list3);
				list3.Sort(new RichPointComparer());
				List<Curve> collection = AreaCreator.SearchLongestPath(list3);
				list.AddRange(collection);
			}
			return list;
		}

		public static Curve ExtendCurve(Curve curve, XYZ pt)
		{
			XYZ endPoint = curve.GetEndPoint(0);
			XYZ endPoint2 = curve.GetEndPoint(1);
			double num = endPoint.DistanceTo(pt);
			double num2 = endPoint2.DistanceTo(pt);
			if (num < 1E-05 || num2 < 1E-05)
			{
				return curve;
			}
			if (num > num2)
			{
				if (curve.GetType() == typeof(Line))
				{
					return Line.CreateBound(endPoint, pt);
				}
				if (curve.GetType() == typeof(Arc))
				{
					return Arc.Create(endPoint, pt, endPoint2);
				}
			}
			else
			{
				if (curve.GetType() == typeof(Line))
				{
					return Line.CreateBound(pt, endPoint2);
				}
				if (curve.GetType() == typeof(Arc))
				{
					return Arc.Create(pt, endPoint2, endPoint);
				}
			}
			return null;
		}

		public static bool GetShortestCurve(Curve curve1, Curve curve2, ref Curve shortestCurve)
		{
			XYZ endPoint = curve1.GetEndPoint(0);
			curve1.GetEndPoint(1);
			XYZ endPoint2 = curve2.GetEndPoint(0);
			curve2.GetEndPoint(1);
			XYZ endPoint3 = curve1.GetEndPoint(1);
			XYZ endPoint4 = curve2.GetEndPoint(0);
			double num = endPoint3.DistanceTo(endPoint4);
			if (num * 304.8 < 0.8)
			{
				shortestCurve = Line.CreateBound(endPoint, endPoint2);
				return false;
			}
			shortestCurve = Line.CreateBound(endPoint3, endPoint4);
			return true;
		}

		public static List<Curve> GetClosedAreaCurves(List<Curve> wallCurves)
		{
			XYZ xyz = XYZ.Zero;
			int i = 0;
			while (i < wallCurves.Count)
			{
				int num = (i + 1) % wallCurves.Count;
				IntersectionResultArray intersectionResultArray;
				SetComparisonResult setComparisonResult = wallCurves[i].Intersect(wallCurves[num], out intersectionResultArray);
				if ((SetComparisonResult)8 == setComparisonResult)
				{
					XYZ endPoint = wallCurves[i].GetEndPoint(0);
					XYZ endPoint2 = wallCurves[i].GetEndPoint(1);
					XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
					if (xyzpoint.DistanceTo(endPoint) <= xyzpoint.DistanceTo(endPoint2))
					{
						if (2 != intersectionResultArray.Size)
						{
							goto IL_CB;
						}
					}
				}
                else if ((SetComparisonResult)64 == setComparisonResult)
				{
					wallCurves.RemoveAt(num);
					i--;
					if (num == 0)
					{
						i--;
					}
				}
				else if (!wallCurves[i].GetEndPoint(1).IsAlmostEqualTo(wallCurves[num].GetEndPoint(0)))
				{
					goto IL_CB;
				}
				IL_1E3:
				i++;
				continue;
				IL_CB:
				Curve curve = wallCurves[i].Clone();
				curve.MakeUnbound();
				Curve curve2 = wallCurves[num].Clone();
				curve2.MakeUnbound();
				setComparisonResult = curve.Intersect(curve2, out intersectionResultArray);
                if ((SetComparisonResult)4 == setComparisonResult || (SetComparisonResult)64 == setComparisonResult)
				{
					Curve item = null;
					bool shortestCurve = AreaCreator.GetShortestCurve(wallCurves[i], wallCurves[num], ref item);
					if (shortestCurve)
					{
						wallCurves.Insert(num, item);
						i++;
						goto IL_1E3;
					}
					wallCurves.RemoveAt(i);
					wallCurves.Insert(i, item);
					goto IL_1E3;
				}
				else
				{
					if ((SetComparisonResult)8 == setComparisonResult)
					{
						xyz = intersectionResultArray.get_Item(0).XYZPoint;
						XYZ endPoint3 = wallCurves[i].GetEndPoint(1);
						if (2 == intersectionResultArray.Size)
						{
							XYZ xyzpoint2 = intersectionResultArray.get_Item(1).XYZPoint;
							if (xyz.DistanceTo(endPoint3) > xyzpoint2.DistanceTo(endPoint3))
							{
								xyz = xyzpoint2;
							}
						}
						Curve item2 = AreaCreator.ExtendCurve(wallCurves[i], xyz);
						wallCurves.RemoveAt(i);
						wallCurves.Insert(i, item2);
						Curve item3 = AreaCreator.ExtendCurve(wallCurves[num], xyz);
						wallCurves.RemoveAt(num);
						wallCurves.Insert(num, item3);
						goto IL_1E3;
					}
					goto IL_1E3;
				}
			}
			return wallCurves;
		}

		public static List<Curve> SearchLongestPath(List<RichPoint> richPoints)
		{
			XYZ xyz = XYZ.BasisY.Negate();
			double num = 0.0;
			List<Curve> list = new List<Curve>();
			if (richPoints.Count == 0)
			{
				return list;
			}
			Curve curve = null;
			XYZ ptCurrent = richPoints[0].m_point;
			do
			{
				RichPoint richPoint = richPoints.Find((RichPoint a) => a.m_point.IsAlmostEqualTo(ptCurrent));
				if (richPoint.m_curves == null)
				{
					break;
				}
				foreach (Curve curve2 in richPoint.m_curves)
				{
					XYZ tangentAt = AreaCreator.GetTangentAt(curve2);
					double num2 = xyz.AngleOnPlaneTo(tangentAt, XYZ.BasisZ);
					if (Math.Round(Math.PI*2, 4) == Math.Round(num2, 4))
					{
						num2 = 0.0;
					}
					if (num2 > num)
					{
						curve = curve2;
						num = num2;
					}
				}
				list.Add(curve);
				ptCurrent = curve.GetEndPoint(1);
				xyz = AreaCreator.GetTangentAt(AreaCreator.CreateReversedCurve(curve));
				num = 0.0;
			}
			while (!ptCurrent.IsAlmostEqualTo(richPoints[0].m_point));
			return list;
		}

		public static XYZ GetTangentAt(Curve curve)
		{
			Transform transform = curve.ComputeDerivatives(0.0, true);
			return transform.BasisX.Normalize();
		}

		public static void RemoveRepeatCurves(List<Curve> curves)
		{
			for (int i = 0; i < curves.Count; i++)
			{
				for (int j = i + 1; j < curves.Count; j++)
				{
					SetComparisonResult setComparisonResult = curves[i].Intersect(curves[j]);
                    if ((SetComparisonResult)64 == setComparisonResult)
					{
						XYZ endPoint = curves[i].GetEndPoint(0);
						XYZ endPoint2 = curves[i].GetEndPoint(1);
						XYZ endPoint3 = curves[j].GetEndPoint(0);
						XYZ endPoint4 = curves[j].GetEndPoint(1);
						if (Math.Abs(curves[i].Length - curves[j].Length) < 1E-05 && ((endPoint.IsAlmostEqualTo(endPoint3) && endPoint2.IsAlmostEqualTo(endPoint4)) || (endPoint.IsAlmostEqualTo(endPoint4) && endPoint2.IsAlmostEqualTo(endPoint3))))
						{
							curves.RemoveAt(j);
							j--;
						}
					}
				}
			}
		}

		public static List<RichPoint> ConstructRichPointSet(List<Curve> splitCurves)
		{
			List<RichPoint> list = new List<RichPoint>();
			foreach (Curve curve in splitCurves)
			{
				XYZ ptStart = curve.GetEndPoint(0);
				int num = list.FindIndex((RichPoint a) => a.m_point.IsAlmostEqualTo(ptStart));
				if (-1 == num)
				{
					list.Add(new RichPoint(ptStart, curve));
				}
				else
				{
					list[num].AddCurve(curve);
				}
				XYZ ptEnd = curve.GetEndPoint(1);
				num = list.FindIndex((RichPoint a) => a.m_point.IsAlmostEqualTo(ptEnd));
				if (-1 == num)
				{
					list.Add(new RichPoint(ptEnd, AreaCreator.CreateReversedCurve(curve)));
				}
				else
				{
					list[num].AddCurve(AreaCreator.CreateReversedCurve(curve));
				}
			}
			return list;
		}

		public static void DeleteSingleEdgePoint(ref List<RichPoint> richPoints)
		{
			for (int i = 0; i < richPoints.Count; i++)
			{
				RichPoint richPoint = richPoints[i];
				if (1 == richPoint.m_curves.Count)
				{
					XYZ endPoint = richPoint.m_curves[0].GetEndPoint(0);
					XYZ ptEnd = richPoint.m_curves[0].GetEndPoint(1);
					richPoints.RemoveAt(i);
					i--;
					RichPoint item = richPoints.Find((RichPoint a) => a.m_point.IsAlmostEqualTo(ptEnd));
					for (int j = 0; j < item.m_curves.Count; j++)
					{
						Curve curve = item.m_curves[j];
						if (curve.GetEndPoint(1).IsAlmostEqualTo(endPoint))
						{
							item.m_curves.RemoveAt(j);
							if (item.m_lstCurveInformationBean.Count > 0)
							{
								item.m_lstCurveInformationBean.RemoveAt(j);
							}
							if (item.m_curves.Count == 0)
							{
								richPoints.Remove(item);
							}
							i = -1;
							break;
						}
					}
				}
			}
			richPoints.TrimExcess();
		}

		public static bool AdjustCurvesWithErrorInfo(ref List<Curve> curves, Document doc)
		{
			List<XYZ> list = new List<XYZ>();
			if (!AreaCreator.AdjustCurves(ref curves, ref list, doc))
			{
				return false;
			}
			if (list.Count > 0)
			{
				string str = list.Count.ToString();
				if (MessageBox.Show("中心线错位小于0.8mm的墙体有" + str + "个，是否处理完再执行(提示线需要自己删除)？", "盈建科提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					AreaCreator.CreateCurvesForErrorPos(list, doc);
					return false;
				}
			}
			return true;
		}

		public static bool AdjustCurves(ref List<Curve> curves, ref List<XYZ> lstPtMiniDist, Document doc)
		{
			lstPtMiniDist = new List<XYZ>();
			List<XYZ> list = new List<XYZ>();
			int i = 0;
			while (i < curves.Count)
			{
				Curve curve = curves[i];
				XYZ endPoint = curve.GetEndPoint(0);
				XYZ xyz = AreaCreator.FindApproximatePoint(list, endPoint);
				if (xyz != null)
				{
					try
					{
						Curve item = AreaCreator.ModifyStartPoint(curve, xyz);
						curves.RemoveAt(i);
						curves.Insert(i, item);
						if (AreaCreator.Is2PointDistLessThan08(xyz, endPoint))
						{
							lstPtMiniDist.Add(xyz);
						}
						goto IL_6A;
					}
					catch
					{
						goto IL_6A;
					}
					goto IL_63;
				}
				goto IL_63;
				IL_6A:
				i++;
				continue;
				IL_63:
				list.Add(endPoint);
				goto IL_6A;
			}
			int j = 0;
			while (j < curves.Count)
			{
				Curve curve2 = curves[j];
				XYZ endPoint2 = curve2.GetEndPoint(1);
				XYZ xyz2 = AreaCreator.FindApproximatePoint(list, endPoint2);
				if (xyz2 != null)
				{
					try
					{
						Curve item2 = AreaCreator.ModifyEndPoint(curve2, xyz2);
						curves.RemoveAt(j);
						curves.Insert(j, item2);
						if (AreaCreator.Is2PointDistLessThan08(xyz2, endPoint2))
						{
							lstPtMiniDist.Add(xyz2);
						}
						goto IL_E0;
					}
					catch
					{
						goto IL_E0;
					}
					goto IL_D8;
				}
				goto IL_D8;
				IL_E0:
				j++;
				continue;
				IL_D8:
				list.Add(endPoint2);
				goto IL_E0;
			}
			for (int k = 0; k < lstPtMiniDist.Count - 1; k++)
			{
				XYZ xyz3 = lstPtMiniDist[k];
				for (int l = k + 1; l < lstPtMiniDist.Count; l++)
				{
					XYZ xyz4 = lstPtMiniDist[l];
					if (xyz3.DistanceTo(xyz4) < AssistFunc.mmToFeet(0.8))
					{
						lstPtMiniDist.RemoveAt(l);
						l--;
					}
				}
			}
			return true;
		}

		public static void CreateCurvesForErrorPos(List<XYZ> lstPtMiniDist, Document doc)
		{
			Transaction transaction = new Transaction(doc);
			transaction.Start("Circle");
			foreach (XYZ pt in lstPtMiniDist)
			{
				AreaCreator.CreateCurvesForErrorPos(pt, doc);
			}
			transaction.Commit();
		}

		public static XYZ FindApproximatePoint(List<XYZ> pts, XYZ ptOrigin)
		{
			foreach (XYZ xyz in pts)
			{
				double num = xyz.DistanceTo(ptOrigin);
				if (num < 0.0328)
				{
					return xyz;
				}
			}
			return null;
		}

		public static bool Is2PointDistLessThan08(XYZ pt1, XYZ pt2)
		{
			double num = pt1.DistanceTo(pt2);
			return num < AssistFunc.mmToFeet(0.8) && num > AssistFunc.mmToFeet(0.001);
		}

		public static Curve ModifyStartPoint(Curve curve, XYZ ptStart)
		{
			if (curve is Line)
			{
				return Line.CreateBound(ptStart, curve.GetEndPoint(1));
			}
			if (curve is Arc)
			{
				return Arc.Create(ptStart, curve.GetEndPoint(1), curve.Evaluate(0.5, true));
			}
			return curve;
		}

		public static Curve ModifyEndPoint(Curve curve, XYZ ptEnd)
		{
			if (curve is Line)
			{
				return Line.CreateBound(curve.GetEndPoint(0), ptEnd);
			}
			if (curve is Arc)
			{
				return Arc.Create(curve.GetEndPoint(0), ptEnd, curve.Evaluate(0.5, true));
			}
			return curve;
		}

		public static Curve CreateReversedCurve(Curve orig)
		{
			if (orig is Line)
			{
				return Line.CreateBound(orig.GetEndPoint(1), orig.GetEndPoint(0));
			}
			if (orig is Arc)
			{
				return Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true));
			}
			throw new Exception("无法创建方向相反的曲线。");
		}

		public static List<Curve> BreakCurves(List<Curve> curves)
		{
			for (int i = 0; i < curves.Count; i++)
			{
				for (int j = i + 1; j < curves.Count; j++)
				{
					IntersectionResultArray intersectionResultArray;
					SetComparisonResult setComparisonResult = curves[i].Intersect(curves[j], out intersectionResultArray);
					if ((SetComparisonResult)8 == setComparisonResult)
					{
						XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
						List<Curve> list = AreaCreator.SplitCurves(curves[j], xyzpoint);
						if (list == null && 2 == intersectionResultArray.Size)
						{
							list = AreaCreator.SplitCurves(curves[j], intersectionResultArray.get_Item(1).XYZPoint);
						}
						if (list != null && list.Count > 0)
						{
							curves.RemoveAt(j);
							curves.AddRange(list);
							j--;
						}
						List<Curve> list2 = AreaCreator.SplitCurves(curves[i], xyzpoint);
						if (list2 == null && 2 == intersectionResultArray.Size)
						{
							list2 = AreaCreator.SplitCurves(curves[i], intersectionResultArray.get_Item(1).XYZPoint);
						}
						if (list2 != null)
						{
							curves.RemoveAt(i);
							curves.AddRange(list2);
							i--;
							break;
						}
					}
				}
			}
			return curves;
		}

		public static List<Curve> SplitCurves(Curve curve, XYZ ptIntersect)
		{
			XYZ endPoint = curve.GetEndPoint(0);
			XYZ endPoint2 = curve.GetEndPoint(1);
			if (ptIntersect.IsAlmostEqualTo(endPoint) || ptIntersect.IsAlmostEqualTo(endPoint2))
			{
				return null;
			}
			List<Curve> list = new List<Curve>();
			if (curve.GetType() == typeof(Line))
			{
				if (ptIntersect.DistanceTo(endPoint) > AssistFunc.mmToFeet(0.8))
				{
					list.Add(Line.CreateBound(endPoint, ptIntersect));
				}
				if (ptIntersect.DistanceTo(endPoint2) > AssistFunc.mmToFeet(0.8))
				{
					list.Add(Line.CreateBound(ptIntersect, endPoint2));
				}
			}
			else if (curve.GetType() == typeof(Arc))
			{
				Arc arc = curve as Arc;
				XYZ center = arc.Center;
				XYZ normal = arc.Normal;
				XYZ xyz = Geometry.CalculatMidPoint(endPoint, ptIntersect, center, normal);
				XYZ xyz2 = Geometry.CalculatMidPoint(ptIntersect, endPoint2, center, normal);
				if (ptIntersect.DistanceTo(endPoint) > AssistFunc.mmToFeet(0.8))
				{
					Arc item = Arc.Create(endPoint, ptIntersect, xyz);
					list.Add(item);
				}
				if (ptIntersect.DistanceTo(endPoint2) > AssistFunc.mmToFeet(0.8))
				{
					Arc item2 = Arc.Create(ptIntersect, endPoint2, xyz2);
					list.Add(item2);
				}
			}
			return list;
		}

		private List<List<Curve>> GetLargestClosedAreas(List<Curve> curves)
		{
			List<Curve> list = AreaCreator.BreakCurves(curves);
			AreaCreator.RemoveRepeatCurves(list);
			List<RichPoint> list2 = AreaCreator.ConstructRichPointSet(list);
			AreaCreator.DeleteSingleEdgePoint(ref list2);
			list2.Sort(new RichPointComparer());
			return this.GetLongestPathAreas(list2);
		}

		private List<ElementId> GetRoomsInArea(List<Curve> areaCurves, List<Room> rooms)
		{
			List<ElementId> list = new List<ElementId>();
			List<XYZ> list2 = new List<XYZ>();
			foreach (Curve curve in areaCurves)
			{
				if (curve != null)
				{
					list2.AddRange(curve.Tessellate());
				}
			}
			foreach (Room room in rooms)
			{
				LocationPoint locationPoint = room.Location as LocationPoint;
				if (1 == Geometry.PointInPloygon(list2, locationPoint.Point, 0.0001, 0.0001))
				{
					list.Add(room.Id);
				}
			}
			return list;
		}

		private DetailCurve CreateDetailCurve(Autodesk.Revit.DB.Document doc, Curve curve, GraphicsStyle lineStyle, LinePatternElement linePattern)
		{
			Transaction transaction = new Transaction(doc, "DrawCurve");
			transaction.Start();
			DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, curve);
			detailCurve.LineStyle = lineStyle;
			OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
			overrideGraphicSettings.SetProjectionLinePatternId(linePattern.Id);
			doc.ActiveView.SetElementOverrides(detailCurve.Id, overrideGraphicSettings);
			transaction.Commit();
			return detailCurve;
		}

		private bool IsClosed(Autodesk.Revit.DB.Document doc, List<ElementId> ids)
		{
			List<Curve> list = new List<Curve>();
			foreach (ElementId elementId in ids)
			{
				DetailCurve detailCurve = doc.GetElement(elementId) as DetailCurve;
				list.Add(detailCurve.GeometryCurve);
			}
			string empty = string.Empty;
			return this.SerializeCurves(list, ref empty);
		}

		private bool SerializeCurves(List<Curve> curves, ref string message)
		{
			if (curves.Count == 0)
			{
				message = "曲线数量为0";
				return false;
			}
			Dictionary<XYZ, List<Curve>> dictionary = new Dictionary<XYZ, List<Curve>>(new XYZEqualityComparer());
			foreach (Curve curve in curves)
			{
				XYZ endPoint = curve.GetEndPoint(0);
				XYZ endPoint2 = curve.GetEndPoint(1);
				if (!dictionary.ContainsKey(endPoint))
				{
					dictionary.Add(endPoint, new List<Curve>
					{
						curve
					});
				}
				else
				{
					List<Curve> list = dictionary[endPoint];
					list.Add(curve);
				}
				if (!dictionary.ContainsKey(endPoint2))
				{
					dictionary.Add(endPoint2, new List<Curve>
					{
						curve
					});
				}
				else
				{
					List<Curve> list2 = dictionary[endPoint2];
					list2.Add(curve);
				}
			}
			foreach (KeyValuePair<XYZ, List<Curve>> keyValuePair in dictionary)
			{
				XYZ key = keyValuePair.Key;
				List<Curve> value = keyValuePair.Value;
				if (value.Count > 2)
				{
					message = "所选参照线重叠或者存在分支";
					return false;
				}
				if (value.Count == 1)
				{
					message = "所选参照线不是环线";
					return false;
				}
			}
			return true;
		}

		private List<ClosedArea> RegroupAreas(List<ClosedArea> selectAreas, List<ClosedArea> existedAreas)
		{
			List<ClosedArea> list = new List<ClosedArea>();
			for (int i = 0; i < selectAreas.Count; i++)
			{
				try
				{
					ClosedArea item = selectAreas[i];
					List<ClosedArea> collection = this.AnalyzeAreas(ref item, existedAreas);
					list.AddRange(collection);
					selectAreas.RemoveAt(i);
					selectAreas.Insert(i, item);
				}
				catch (Exception)
				{
				}
			}
			return list;
		}

		private List<ClosedArea> AnalyzeAreas(ref ClosedArea selectArea, List<ClosedArea> existedAreas)
		{
			List<ClosedArea> list = new List<ClosedArea>();
			for (int i = 0; i < existedAreas.Count; i++)
			{
				ClosedArea closedArea = existedAreas[i];
				AreaCreator.AreaClip areaClip = this.AnalyzeClipAreas(selectArea, closedArea);
				if (AreaCreator.AreaClip.Equal == areaClip)
				{
					selectArea.m_areaId = ElementId.InvalidElementId;
					return list;
				}
				if (areaClip != AreaCreator.AreaClip.Separation && AreaCreator.AreaClip.Tangent != areaClip)
				{
					if (AreaCreator.AreaClip.Intersection == areaClip)
					{
						Common.DeleteArea(this.m_doc, closedArea.m_areaId);
						List<ClosedArea> list2 = this.ClipAreas(ref closedArea, selectArea);
						if (list2 != null && list2.Count > 0)
						{
							list.AddRange(list2);
						}
					}
					else
					{
						if (AreaCreator.AreaClip.SubSet == areaClip)
						{
							Common.DeleteArea(this.m_doc, closedArea.m_areaId);
							List<ClosedArea> list3 = this.ClipAreas(ref closedArea, selectArea);
							if (list3 != null && list3.Count > 0)
							{
								list.AddRange(list3);
							}
							return list;
						}
						if (AreaCreator.AreaClip.SuperSet == areaClip)
						{
							Common.DeleteArea(this.m_doc, closedArea.m_areaId);
						}
					}
				}
			}
			return list;
		}

		private void DeteleRepeatCurves(List<Curve> oriCurves)
		{
			List<Curve> list = new List<Curve>();
			foreach (Curve curve in oriCurves)
			{
				bool flag = false;
				foreach (Curve c in list)
				{
					if (OverlapType.eOverlap == CurveAssistFunc.GetOverlapType(this.m_Revit.Application, curve, c) || OverlapType.ePartOverlap == CurveAssistFunc.GetOverlapType(this.m_Revit.Application, curve, c) || OverlapType.e1Cover2 == CurveAssistFunc.GetOverlapType(this.m_Revit.Application, curve, c) || OverlapType.e2Cover1 == CurveAssistFunc.GetOverlapType(this.m_Revit.Application, curve, c))
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					list.Add(curve);
				}
			}
			oriCurves.Clear();
			oriCurves.AddRange(list);
		}

		private List<ClosedArea> ClipAreas(ref ClosedArea area1, ClosedArea area2)
		{
			Curve curve = null;
			Curve curve2 = null;
			CurveLoop curveLoop = new CurveLoop();
			for (int i = 0; i < area1.m_outerBoundary.Count; i++)
			{
				try
				{
					if (i > 0)
					{
						curve = area1.m_outerBoundary[i - 1];
					}
					curve2 = area1.m_outerBoundary[i];
					curveLoop.Append(curve2);
				}
				catch (Exception)
				{
					if (curve2 is Line)
					{
						Line line = Line.CreateBound(curve.GetEndPoint(1), curve2.GetEndPoint(1));
						curveLoop.Append(line);
					}
					else if (curve2 is Arc)
					{
						XYZ xyz = Geometry.CalculatMidPoint(curve2 as Arc);
						Arc arc = Arc.Create(curve.GetEndPoint(1), curve2.GetEndPoint(1), xyz);
						curveLoop.Append(arc);
					}
				}
			}
			CurveLoop curveLoop2 = new CurveLoop();
			foreach (Curve curve3 in area2.m_outerBoundary)
			{
				curveLoop2.Append(curve3);
			}
			List<CurveLoop> inputLstHoles = null;
			List<CurveLoop> inputLstHoles2 = null;
			if (area1.m_innerBoundary != null && area1.m_innerBoundary.Count > 0)
			{
				inputLstHoles = new List<CurveLoop>();
			}
			if (area2.m_innerBoundary != null && area2.m_innerBoundary.Count > 0)
			{
				inputLstHoles2 = new List<CurveLoop>();
			}
			RevitPolygonDataBean inputOne = new RevitPolygonDataBean(curveLoop, inputLstHoles);
			RevitPolygonDataBean inputTwo = new RevitPolygonDataBean(curveLoop2, inputLstHoles2);
			List<RevitPolygonDataBean> list = null;
			RevitPolygonBooleanOperater revitPolygonBooleanOperater = new RevitPolygonBooleanOperater();
			revitPolygonBooleanOperater.TryGetBooleanResult(inputOne, inputTwo, BooleanOperatorKindEnum.Difference, out list);
			List<List<Curve>> list2 = new List<List<Curve>>();
			foreach (RevitPolygonDataBean revitPolygonDataBean in list)
			{
				List<Curve> list3 = new List<Curve>();
				foreach (Curve item in revitPolygonDataBean.ShellCurveLoop)
				{
					list3.Add(item);
				}
				list2.Add(list3);
			}
			List<ClosedArea> result;
			try
			{
				List<ClosedArea> list4 = new List<ClosedArea>();
				foreach (List<Curve> list5 in list2)
				{
					try
					{
						double value = this.CalculateArea(list5);
						if (Math.Abs(value) < 1.0)
						{
							continue;
						}
					}
					catch
					{
					}
					ClosedArea closedArea = new ClosedAreaMoreInformation();
					closedArea.m_outerBoundary = new List<Curve>();
					closedArea.m_outerBoundary.AddRange(list5);
					closedArea.m_innerBoundary = new List<List<Curve>>();
					closedArea.m_fireZoneInfo = default(FireZoneInfo);
					closedArea.m_fireZoneInfo.m_prefix = area1.m_fireZoneInfo.m_prefix;
					closedArea.m_fireZoneInfo.m_name = area1.m_fireZoneInfo.m_name;
					closedArea.m_fireZoneInfo.m_number = area1.m_fireZoneInfo.m_number;
					closedArea.m_fireZoneInfo.m_suffix = area1.m_fireZoneInfo.m_suffix;
					closedArea.m_fireZoneInfo.m_remark = area1.m_fireZoneInfo.m_remark;
					list4.Add(closedArea);
				}
				area1 = list4[0];
				result = list4;
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}

		private Polygon ConstructPolygon(ClosedArea area1)
		{
			return GpcPolygonController.ConstructPolygon(area1.m_outerBoundary, area1.m_innerBoundary);
		}

		private AreaCreator.AreaClip AnalyzeClipAreas(ClosedArea area1, ClosedArea area2)
		{
			try
			{
				Polygon polygon = this.ConstructPolygon(area1);
				Polygon polygon2 = this.ConstructPolygon(area2);
				GraphicsPath graphicsPath = polygon.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				GraphicsPath graphicsPath2 = polygon2.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				IPolygon polygon3 = polygon.ClipPolygon(polygon2, ClipOp.Int);
				GraphicsPath graphicsPath3 = polygon3.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				IPolygon polygon4 = polygon.ClipPolygon(polygon2, ClipOp.Xor);
				GraphicsPath graphicsPath4 = polygon4.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				IPolygon polygon5 = polygon.ClipPolygon(polygon2, ClipOp.Diff);
				GraphicsPath graphicsPath5 = polygon5.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				IPolygon polygon6 = polygon2.ClipPolygon(polygon, ClipOp.Diff);
				GraphicsPath graphicsPath6 = polygon6.ToGraphicsPath(ContourType.All, GraphicsPathType.Lines);
				double value = 1.0;
				double value2 = 1.0;
				double value3 = 1.0;
				double value4 = 1.0;
				double value5 = 1.0;
				try
				{
					value4 = this.CalculateArea(graphicsPath.PathPoints);
					value5 = this.CalculateArea(graphicsPath2.PathPoints);
					value = this.CalculateArea(graphicsPath5.PathPoints);
					value2 = this.CalculateArea(graphicsPath6.PathPoints);
					value3 = this.CalculateArea(graphicsPath3.PathPoints);
				}
				catch (Exception)
				{
				}
				if (graphicsPath3.PointCount < 1)
				{
					return AreaCreator.AreaClip.Separation;
				}
				if (graphicsPath4.PointCount < 1)
				{
					return AreaCreator.AreaClip.Equal;
				}
				if (graphicsPath5.PointCount > 1 && (graphicsPath6.PointCount < 1 || Math.Abs(value2) < 1.0))
				{
					return AreaCreator.AreaClip.SuperSet;
				}
				if (graphicsPath6.PointCount > 1 && (graphicsPath5.PointCount < 1 || Math.Abs(value) < 1.0))
				{
					return AreaCreator.AreaClip.SubSet;
				}
				if (graphicsPath5.PointCount > 1 && graphicsPath6.PointCount > 1 && Math.Abs(value3) < 0.01 * Math.Abs(value4) && Math.Abs(value3) < 0.01 * Math.Abs(value5))
				{
					return AreaCreator.AreaClip.Separation;
				}
				if (graphicsPath5.PointCount > 1 && graphicsPath6.PointCount > 1)
				{
					return AreaCreator.AreaClip.Intersection;
				}
			}
			catch (Exception)
			{
			}
			return AreaCreator.AreaClip.Intersection;
		}

		private double CalculateArea(PointF[] points)
		{
			List<double> list = new List<double>();
			List<double> list2 = new List<double>();
			foreach (PointF pointF in points)
			{
				list.Add((double)pointF.X);
				list2.Add((double)pointF.Y);
			}
			return Geometry.AoArea(list.Count, list.ToArray(), list2.ToArray());
		}

		private double CalculateArea(List<Curve> curves)
		{
			List<double> list = new List<double>();
			List<double> list2 = new List<double>();
			foreach (Curve curve in curves)
			{
				if (!(curve == null))
				{
					XYZ endPoint = curve.GetEndPoint(0);
					list.Add(endPoint.X);
					list2.Add(endPoint.Y);
				}
			}
			return Geometry.AoArea(list.Count, list.ToArray(), list2.ToArray());
		}

		private List<ClosedArea> GetFireZoneBoundary(Autodesk.Revit.DB.Document doc)
		{
			List<ClosedArea> list = new List<ClosedArea>();
			List<Area> list2 = Common.FilterFireAreas(doc);
			foreach (Area area in list2)
			{
				ClosedArea fireZoneBoundaryCurves = this.GetFireZoneBoundaryCurves(area);
				list.Add(fireZoneBoundaryCurves);
			}
			return list;
		}

		private ClosedArea GetFireZoneBoundaryCurves(Area area)
		{
			ClosedArea closedArea = new ClosedArea();
			closedArea.m_outerBoundary = new List<Curve>();
			closedArea.m_innerBoundary = new List<List<Curve>>();
			closedArea.m_areaId = area.Id;
			closedArea.m_fireZoneInfo = default(FireZoneInfo);
			Parameter parameter = area.GetParameter("区域前缀");
			if (parameter != null)
			{
				closedArea.m_fireZoneInfo.m_prefix = parameter.AsString();
			}
			Parameter parameter2 = area.GetParameter("名称");
			if (parameter2 != null)
			{
				closedArea.m_fireZoneInfo.m_name = parameter2.AsString();
			}
			Parameter parameter3 = area.GetParameter("区域编号");
			if (parameter3 != null)
			{
				closedArea.m_fireZoneInfo.m_number = parameter3.AsString();
			}
			Parameter parameter4 = area.GetParameter("区域后缀");
			if (parameter4 != null)
			{
				closedArea.m_fireZoneInfo.m_suffix = parameter4.AsString();
			}
			Parameter parameter5 = area.GetParameter("注释");
			if (parameter5 != null)
			{
				closedArea.m_fireZoneInfo.m_remark = parameter5.AsString();
			}
			bool flag = true;
			IList<IList<BoundarySegment>> boundarySegments = area.GetBoundarySegments(new SpatialElementBoundaryOptions());
			foreach (IList<BoundarySegment> list in boundarySegments)
			{
				if (flag)
				{
					foreach (BoundarySegment segment in list)
					{
						closedArea.m_outerBoundary.Add(segment.GetCurve());
					}
					flag = false;
				}
				else
				{
					List<Curve> list2 = new List<Curve>();
					foreach (BoundarySegment segment2 in list)
					{
						list2.Add(segment2.GetCurve());
					}
					closedArea.m_innerBoundary.Add(list2);
				}
			}
			return closedArea;
		}

		private List<List<Curve>> GetInnerAreas(Autodesk.Revit.DB.Document doc)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			Transaction transaction = new Transaction(doc, "test");
			transaction.Start();
			PlanTopology planTopology = doc.get_PlanTopology(doc.ActiveView.GenLevel);
			foreach (object obj in planTopology.Circuits)
			{
				PlanCircuit planCircuit = (PlanCircuit)obj;
				if (!planCircuit.IsRoomLocated)
				{
					try
					{
						Room room = doc.Create.NewRoom(null, planCircuit);
						List<Curve> roomClosedCurves = this.GetRoomClosedCurves(room);
						if (roomClosedCurves.Count > 0)
						{
							list.Add(roomClosedCurves);
						}
					}
					catch
					{
					}
				}
			}
			transaction.RollBack();
			List<Curve> list2 = new List<Curve>();
			foreach (List<Curve> collection in list)
			{
				list2.AddRange(collection);
			}
			List<Curve> list3 = AreaCreator.BreakCurves(list2);
			AreaCreator.RemoveRepeatCurves(list3);
			List<RichPoint> list4 = AreaCreator.ConstructRichPointSet(list3);
			AreaCreator.DeleteSingleEdgePoint(ref list4);
			list4.Sort(new RichPointComparer());
			return this.GetLongestPathAreas(list4);
		}

		private List<List<CurveInformationBean>> GetInnerAreaBeans(Autodesk.Revit.DB.Document doc)
		{
			List<List<CurveInformationBean>> list = new List<List<CurveInformationBean>>();
			Transaction transaction = new Transaction(doc, "test");
			transaction.Start();
			PlanTopology planTopology = doc.get_PlanTopology(doc.ActiveView.GenLevel);
			foreach (object obj in planTopology.Circuits)
			{
				PlanCircuit planCircuit = (PlanCircuit)obj;
				if (!planCircuit.IsRoomLocated)
				{
					try
					{
						Room room = doc.Create.NewRoom(null, planCircuit);
						List<CurveInformationBean> roomClosedCurveInformationBeans = this.GetRoomClosedCurveInformationBeans(room);
						if (roomClosedCurveInformationBeans.Count > 0)
						{
							list.Add(roomClosedCurveInformationBeans);
						}
					}
					catch
					{
					}
				}
			}
			transaction.RollBack();
			List<CurveInformationBean> list2 = new List<CurveInformationBean>();
			foreach (List<CurveInformationBean> collection in list)
			{
				list2.AddRange(collection);
			}
			List<CurveInformationBean> list3 = AreaCreator.BreakCurves(list2);
			AreaCreator.RemoveRepeatCurves(list3);
			List<RichPoint> list4 = AreaCreator.ConstructRichPointSet(list3);
			AreaCreator.DeleteSingleEdgePoint(ref list4);
			list4.Sort(new RichPointComparer());
			return this.GetLongestPathBeanAreas(list4);
		}

		private bool CreateFireZone(Autodesk.Revit.DB.Document doc, ClosedArea closedArea, FireZoneInfo fireZoneInfo, FireZoneLableInfo labelInfo, LinePatternElement linePattern, bool bExistArea = false)
		{
			List<ElementId> list = new List<ElementId>();
			new OffsetWallLine(this.m_Revit, "CenterLine");
			if (bExistArea)
			{
				Area area = Common.CreateArea(doc, closedArea, labelInfo, linePattern, ref list);
				Transaction transaction = new Transaction(doc, "Set Parameters");
				transaction.Start();
				this.SetFireZoneParameters(doc, area, closedArea.m_fireZoneInfo);
				doc.Regenerate();
				XYZ ptCenter = null;
				this.SetFireZoneTag(doc, ptCenter, area, closedArea.m_fireZoneInfo, labelInfo);
				list.Add(area.Id);
				if (list.Count > 0)
				{
					ElementTransformUtils.MoveElements(doc, list, XYZ.BasisX * AssistFunc.mmToFeet(1.0));
					ElementTransformUtils.MoveElements(doc, list, XYZ.BasisX * AssistFunc.mmToFeet(-1.0));
				}
				transaction.Commit();
			}
			else
			{
				Area area2 = Common.CreateArea(doc, closedArea, labelInfo, linePattern, ref list);
				Transaction transaction2 = new Transaction(doc, "Set Parameters");
				transaction2.Start();
				this.SetFireZoneParameters(doc, area2, fireZoneInfo);
				doc.Regenerate();
				XYZ ptCenter2 = null;
				this.SetFireZoneTag(doc, ptCenter2, area2, fireZoneInfo, labelInfo);
				list.Add(area2.Id);
				if (list.Count > 0)
				{
					ElementTransformUtils.MoveElements(doc, list, XYZ.BasisX * AssistFunc.mmToFeet(1.0));
					ElementTransformUtils.MoveElements(doc, list, XYZ.BasisX * AssistFunc.mmToFeet(-1.0));
				}
				transaction2.Commit();
			}
			return true;
		}

		private void AddAreaTag(Autodesk.Revit.DB.Document doc, XYZ ptCenter, Area area, InsideAreaLableInfo labelInfo)
		{
			LocationPoint locationPoint = area.Location as LocationPoint;
			UV uv = new UV(locationPoint.Point.X, locationPoint.Point.Y);
			ViewPlan viewPlan = doc.ActiveView as ViewPlan;
			List<string> insideLabels = this.GetInsideLabels(area, labelInfo);
			this.LoadAreaTagFamily(doc);
			if (1 == insideLabels.Count)
			{
				AreaTag areaTag = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName = this.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag.AreaTagType = areaTagTypeByName;
				areaTag.GetParameter("引线").Set(0);
				return;
			}
			if (2 == insideLabels.Count)
			{
				AreaTag areaTag2 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName2 = this.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag2.AreaTagType = areaTagTypeByName2;
				areaTag2.GetParameter("引线").Set(0);
				UV uv2 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag3 = doc.Create.NewAreaTag(viewPlan, area, uv2);
				AreaTagType areaTagTypeByName3 = this.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag3.AreaTagType = areaTagTypeByName3;
				areaTag3.GetParameter("引线").Set(0);
				return;
			}
			if (3 == insideLabels.Count)
			{
				UV uv3 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag4 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName4 = this.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag4.AreaTagType = areaTagTypeByName4;
				areaTag4.GetParameter("引线").Set(0);
				AreaTag areaTag5 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName5 = this.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag5.AreaTagType = areaTagTypeByName5;
				areaTag5.GetParameter("引线").Set(0);
				uv3 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag6 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName6 = this.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag6.AreaTagType = areaTagTypeByName6;
				areaTag6.GetParameter("引线").Set(0);
				return;
			}
			if (4 == insideLabels.Count)
			{
				UV uv4 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag7 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName7 = this.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag7.AreaTagType = areaTagTypeByName7;
				areaTag7.GetParameter("引线").Set(0);
				AreaTag areaTag8 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName8 = this.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag8.AreaTagType = areaTagTypeByName8;
				areaTag8.GetParameter("引线").Set(0);
				uv4 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag9 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName9 = this.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag9.AreaTagType = areaTagTypeByName9;
				areaTag9.GetParameter("引线").Set(0);
				uv4 = new UV(uv.U, uv.V - 2.8);
				AreaTag areaTag10 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName10 = this.GetAreaTagTypeByName(doc, insideLabels[3]);
				areaTag10.AreaTagType = areaTagTypeByName10;
				areaTag10.GetParameter("引线").Set(0);
				return;
			}
			if (5 == insideLabels.Count)
			{
				UV uv5 = new UV(uv.U, uv.V + 2.8);
				AreaTag areaTag11 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName11 = this.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag11.AreaTagType = areaTagTypeByName11;
				areaTag11.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag12 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName12 = this.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag12.AreaTagType = areaTagTypeByName12;
				areaTag12.GetParameter("引线").Set(0);
				AreaTag areaTag13 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName13 = this.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag13.AreaTagType = areaTagTypeByName13;
				areaTag13.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag14 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName14 = this.GetAreaTagTypeByName(doc, insideLabels[3]);
				areaTag14.AreaTagType = areaTagTypeByName14;
				areaTag14.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V - 2.8);
				AreaTag areaTag15 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName15 = this.GetAreaTagTypeByName(doc, insideLabels[4]);
				areaTag15.AreaTagType = areaTagTypeByName15;
				areaTag15.GetParameter("引线").Set(0);
			}
		}

		private void SetFireZoneTag(Autodesk.Revit.DB.Document doc, XYZ ptCenter, Area area, FireZoneInfo fireZoneInfo, FireZoneLableInfo labelInfo)
		{
			LocationPoint locationPoint = area.Location as LocationPoint;
			ptCenter = locationPoint.Point;
			UV uv = new UV(ptCenter.X, ptCenter.Y);
			ViewPlan viewPlan = doc.ActiveView as ViewPlan;
			List<string> fireZoneLabels = this.GetFireZoneLabels(fireZoneInfo, labelInfo);
			this.LoadAreaTagFamily(doc);
			if (1 == fireZoneLabels.Count)
			{
				AreaTag areaTag = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName = this.GetAreaTagTypeByName(doc, fireZoneLabels[0]);
				areaTag.AreaTagType = areaTagTypeByName;
				areaTag.GetParameter("引线").Set(0);
				return;
			}
			if (2 == fireZoneLabels.Count)
			{
				AreaTag areaTag2 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName2 = this.GetAreaTagTypeByName(doc, fireZoneLabels[0]);
				areaTag2.AreaTagType = areaTagTypeByName2;
				areaTag2.GetParameter("引线").Set(0);
				UV uv2 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag3 = doc.Create.NewAreaTag(viewPlan, area, uv2);
				AreaTagType areaTagTypeByName3 = this.GetAreaTagTypeByName(doc, fireZoneLabels[1]);
				areaTag3.AreaTagType = areaTagTypeByName3;
				areaTag3.GetParameter("引线").Set(0);
				return;
			}
			if (3 == fireZoneLabels.Count)
			{
				UV uv3 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag4 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName4 = this.GetAreaTagTypeByName(doc, fireZoneLabels[0]);
				areaTag4.AreaTagType = areaTagTypeByName4;
				areaTag4.GetParameter("引线").Set(0);
				AreaTag areaTag5 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName5 = this.GetAreaTagTypeByName(doc, fireZoneLabels[1]);
				areaTag5.AreaTagType = areaTagTypeByName5;
				areaTag5.GetParameter("引线").Set(0);
				uv3 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag6 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName6 = this.GetAreaTagTypeByName(doc, fireZoneLabels[2]);
				areaTag6.AreaTagType = areaTagTypeByName6;
				areaTag6.GetParameter("引线").Set(0);
			}
		}

		private List<string> GetInsideLabels(Area area, InsideAreaLableInfo labelInfo)
		{
			string text = area.GetParameter("名称").AsString();
			string text2 = area.GetParameter("区域编号").AsString();
			string text3 = area.GetParameter("区域单元").AsString();
			string text4 = area.GetParameter("区域楼号").AsString();
			List<string> list = new List<string>();
			if (labelInfo.m_labelHouseName && text.Length > 0)
			{
				list.Add("名称");
			}
			if (labelInfo.m_labelHouseNum && text2.Length > 0)
			{
				list.Add("编号");
			}
			if (labelInfo.m_labelUnit && text3.Length > 0)
			{
				list.Add("单元");
			}
			if (labelInfo.m_labelBuildingNum && text4.Length > 0)
			{
				list.Add("楼号");
			}
			if (labelInfo.m_labelInsideArea)
			{
				list.Add("面积" + labelInfo.m_labelLanguage);
			}
			return list;
		}

		private List<string> GetFireZoneLabels(FireZoneInfo fireZoneInfo, FireZoneLableInfo labelInfo)
		{
			List<string> list = new List<string>();
			if ((fireZoneInfo.m_prefix != null && fireZoneInfo.m_prefix.Length > 0) || (fireZoneInfo.m_name != null && fireZoneInfo.m_name.Length > 0) || (fireZoneInfo.m_number != null && fireZoneInfo.m_number.Length > 0) || (fireZoneInfo.m_suffix != null && fireZoneInfo.m_suffix.Length > 0))
			{
				if (labelInfo.m_name && labelInfo.m_number)
				{
					string item = "前缀_名称_编号_后缀";
					list.Add(item);
				}
				else if (labelInfo.m_name)
				{
					string item2 = "前缀_名称_后缀";
					list.Add(item2);
				}
				else if (labelInfo.m_number)
				{
					string item3 = "前缀_编号_后缀";
					list.Add(item3);
				}
			}
			if (labelInfo.m_area)
			{
				list.Add("面积" + labelInfo.m_language);
			}
			if (labelInfo.m_remark && fireZoneInfo.m_remark != null && fireZoneInfo.m_remark.Length > 0)
			{
				list.Add("备注");
			}
			return list;
		}

		private void LoadAreaTagFamily(Autodesk.Revit.DB.Document doc)
		{
			string text = Product.InstallLocation + "\\FamilyLib\\Family";
			string versionNumber = doc.Application.VersionNumber;
			string text2 = "盈建科面积标记";
			text = string.Concat(new string[]
			{
				text,
				"\\",
				versionNumber,
				"\\RoomTag\\",
				text2,
				".rfa"
			});
			if (!File.Exists(text))
			{
				YJKMessageBox.Show(text + "文件不存在。");
			}
			doc.LoadFamily(text);
		}

		private AreaTagType GetAreaTagTypeByName(Autodesk.Revit.DB.Document doc, string symbolName)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			IList<Element> list = filteredElementCollector.OfClass(typeof(FamilySymbol)).ToElements();
			foreach (Element element in list)
			{
				AreaTagType areaTagType = element as AreaTagType;
				if (areaTagType != null && symbolName.ToUpper().CompareTo(areaTagType.Name.ToUpper()) == 0)
				{
					return areaTagType;
				}
			}
			return null;
		}

		private void AddSharedParaToArea(Autodesk.Revit.DB.Document doc, Area area, Room room)
		{
            BuiltInCategory integerValue = (BuiltInCategory)area.Category.Id.IntegerValue;
			Dictionary<string, ParameterType> dictionary = new Dictionary<string, ParameterType>();
			if (area.GetParameter("区域单元") == null)
			{
                dictionary.Add("区域单元", (ParameterType)1);
			}
			if (area.GetParameter("区域楼号") == null)
			{
                dictionary.Add("区域楼号", (ParameterType)1);
			}
			if (area.GetParameter("区域编号") == null)
			{
                dictionary.Add("区域编号", (ParameterType)1);
			}
			if (dictionary.Count > 0)
			{
				SharedParameter.InsertSharedParameter(doc, integerValue, "区域信息", dictionary, true, true);
			}
			string text = room.GetParameter("户型名称").AsString().Trim();
			string text2 = room.GetParameter("户型编号").AsString().Trim();
			string text3 = room.GetParameter("单元").AsString().Trim();
			string text4 = room.GetParameter("楼号").AsString().Trim();
			area.GetParameter("区域编号").Set(text2);
			area.GetParameter("区域单元").Set(text3);
			area.GetParameter("区域楼号").Set(text4);
			area.GetParameter("名称").Set(text);
		}

		private void SetFireZoneParameters(Autodesk.Revit.DB.Document doc, Area area, FireZoneInfo fireZoneInfo)
		{
            BuiltInCategory integerValue = (BuiltInCategory)area.Category.Id.IntegerValue;
			Dictionary<string, ParameterType> dictionary = new Dictionary<string, ParameterType>();
			if (area.GetParameter("区域前缀") == null)
			{
                dictionary.Add("区域前缀", (ParameterType)1);
			}
			if (area.GetParameter("区域编号") == null)
			{
                dictionary.Add("区域编号", (ParameterType)1);
			}
			if (area.GetParameter("区域后缀") == null)
			{
                dictionary.Add("区域后缀", (ParameterType)1);
			}
			if (dictionary.Count > 0)
			{
				SharedParameter.InsertSharedParameter(doc, integerValue, "区域信息", dictionary, true, true);
			}
			area.GetParameter("区域前缀").Set(fireZoneInfo.m_prefix);
			area.GetParameter("区域编号").Set(fireZoneInfo.m_number);
			area.GetParameter("区域后缀").Set(fireZoneInfo.m_suffix);
			area.GetParameter("名称").Set(fireZoneInfo.m_name);
			area.GetParameter("注释").Set(fireZoneInfo.m_remark);
		}

		private List<List<Curve>> GetLongestPathAreas(List<RichPoint> richPoints)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			while (richPoints.Count > 1)
			{
				List<Curve> list2 = AreaCreator.SearchLongestPath(richPoints);
				list.Add(list2);
				List<XYZ> list3 = new List<XYZ>();
				foreach (Curve curve in list2)
				{
					list3.AddRange(curve.Tessellate());
				}
				for (int i = 0; i < richPoints.Count; i++)
				{
					if (-1 != Geometry.PointInPloygon(list3, richPoints[i].m_point, 0.0001, 0.0001))
					{
						richPoints.RemoveAt(i);
						i--;
					}
				}
			}
			return list;
		}

		private List<ClosedArea> GetAllAreas(List<List<Curve>> outerAreas, List<List<Curve>> innerAreas)
		{
			List<ClosedArea> list = new List<ClosedArea>();
			foreach (List<Curve> list2 in outerAreas)
			{
				ClosedArea closedArea = new ClosedArea();
				closedArea.m_outerBoundary = new List<Curve>();
				closedArea.m_outerBoundary.AddRange(list2);
				closedArea.m_innerBoundary = new List<List<Curve>>();
				foreach (List<Curve> list3 in innerAreas)
				{
					if (this.IsSuperset(list2, list3))
					{
						closedArea.m_innerBoundary.Add(list3);
					}
				}
				list.Add(closedArea);
			}
			return list;
		}

		private List<ClosedAreaMoreInformation> GetAllAreas(List<List<CurveInformationBean>> outerAreas, List<List<CurveInformationBean>> innerAreas)
		{
			List<ClosedAreaMoreInformation> list = new List<ClosedAreaMoreInformation>();
			foreach (List<CurveInformationBean> list2 in outerAreas)
			{
				ClosedAreaMoreInformation closedAreaMoreInformation = new ClosedAreaMoreInformation();
				closedAreaMoreInformation.AddLstOuterBoundaryBean(list2);
				foreach (List<CurveInformationBean> list3 in innerAreas)
				{
					if (this.IsSuperset((from n in list2
					select n.ThisCurve).ToList<Curve>(), (from n in list3
					select n.ThisCurve).ToList<Curve>()))
					{
						closedAreaMoreInformation.AddLstInnerBoundaryBean(list3);
					}
				}
				list.Add(closedAreaMoreInformation);
			}
			return list;
		}

		private bool IsSuperset(List<Curve> outerArea, List<Curve> innerArea)
		{
			foreach (Curve curve in innerArea)
			{
				XYZ endPoint = curve.GetEndPoint(0);
				if (!Common.IsPointInArea(outerArea, endPoint))
				{
					return false;
				}
			}
			return true;
		}

		private int PointInArea(List<Curve> area, XYZ pt)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (Curve curve in area)
			{
				list.AddRange(curve.Tessellate());
			}
			return Geometry.PointInPloygon(list, pt, 0.0001, 0.0001);
		}

		private List<ClosedArea> GetClosedAreas(List<RichPoint> richPoints)
		{
			List<ClosedArea> list = new List<ClosedArea>();
			while (richPoints.Count > 1)
			{
				List<Curve> list2 = AreaCreator.SearchLongestPath(richPoints);
				int num = -1;
				if (list.Count > 0)
				{
					ClosedArea closedArea = list[list.Count - 1];
					List<XYZ> list3 = new List<XYZ>();
					foreach (Curve curve in closedArea.m_outerBoundary)
					{
						list3.AddRange(curve.Tessellate());
					}
					XYZ endPoint = list2[0].GetEndPoint(0);
					num = Geometry.PointInPloygon(list3, endPoint, 0.0001, 0.0001);
				}
				if (1 == num)
				{
					list[list.Count - 1].m_innerBoundary.Add(list2);
				}
				else if (-1 == num)
				{
					ClosedArea closedArea2 = new ClosedArea();
					closedArea2.m_outerBoundary = new List<Curve>();
					closedArea2.m_outerBoundary.AddRange(list2);
					closedArea2.m_innerBoundary = new List<List<Curve>>();
					list.Add(closedArea2);
				}
				foreach (Curve curve2 in list2)
				{
					XYZ ptStart = curve2.GetEndPoint(0);
					int num2 = richPoints.FindIndex((RichPoint a) => a.m_point.IsAlmostEqualTo(ptStart));
					if (-1 != num2)
					{
						foreach (Curve curve3 in richPoints[num2].m_curves)
						{
							XYZ ptEnd = curve3.GetEndPoint(1);
							RichPoint richPoint = richPoints.Find((RichPoint a) => a.m_point.IsAlmostEqualTo(ptEnd));
							for (int i = 0; i < richPoint.m_curves.Count; i++)
							{
								if (richPoint.m_curves[i].GetEndPoint(1).IsAlmostEqualTo(ptStart))
								{
									richPoint.m_curves.RemoveAt(i);
									break;
								}
							}
						}
						richPoints.RemoveAt(num2);
					}
				}
				AreaCreator.DeleteSingleEdgePoint(ref richPoints);
			}
			return list;
		}

		private List<Curve> GetRoomCurves(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			Dictionary<int, List<List<Curve>>> wallInstanceCurve = this.GetWallInstanceCurve(doc, rooms);
			List<Curve> list = new List<Curve>();
			foreach (Room room in rooms)
			{
				List<int> wallIds = this.GetWallIds(room);
				List<Curve> wallCurves = AreaCreator.GetWallCurves(room, doc);
				List<Curve> closedAreaCurves = AreaCreator.GetClosedAreaCurves(wallCurves);
				List<Curve> list2 = AreaCreator.BreakCurves(closedAreaCurves);
				AreaCreator.RemoveRepeatCurves(list2);
				List<RichPoint> list3 = AreaCreator.ConstructRichPointSet(list2);
				AreaCreator.DeleteSingleEdgePoint(ref list3);
				list3.Sort(new RichPointComparer());
				List<Curve> list4 = AreaCreator.SearchLongestPath(list3);
				list.AddRange(list4);
				foreach (int key in wallIds)
				{
					if (wallInstanceCurve.ContainsKey(key))
					{
						List<Curve> roomWallInstanceCurves = this.GetRoomWallInstanceCurves(list4, wallInstanceCurve[key]);
						list.AddRange(roomWallInstanceCurves);
					}
				}
			}
			return list;
		}

		private List<Curve> GetRoomClosedCurves(Room room)
		{
			List<Curve> list = new List<Curve>();
			List<Curve> innerWallCurves = this.GetInnerWallCurves(room);
			if (innerWallCurves.Count == 0)
			{
				return list;
			}
			List<Curve> closedAreaCurves = AreaCreator.GetClosedAreaCurves(innerWallCurves);
			List<Curve> list2 = AreaCreator.BreakCurves(closedAreaCurves);
			AreaCreator.RemoveRepeatCurves(list2);
			List<RichPoint> list3 = AreaCreator.ConstructRichPointSet(list2);
			AreaCreator.DeleteSingleEdgePoint(ref list3);
			if (list3.Count == 0)
			{
				return list;
			}
			list3.Sort(new RichPointComparer());
			List<Curve> collection = AreaCreator.SearchLongestPath(list3);
			list.AddRange(collection);
			return list;
		}

		private List<CurveInformationBean> GetRoomClosedCurveInformationBeans(Room room)
		{
			List<CurveInformationBean> list = new List<CurveInformationBean>();
			List<CurveInformationBean> innerWallCurveBeans = this.GetInnerWallCurveBeans(room);
			if (innerWallCurveBeans.Count == 0)
			{
				return list;
			}
			List<CurveInformationBean> closedAreaCurves = AreaCreator.GetClosedAreaCurves(innerWallCurveBeans);
			List<CurveInformationBean> list2 = AreaCreator.BreakCurves(closedAreaCurves);
			AreaCreator.RemoveRepeatCurves(list2);
			List<RichPoint> list3 = AreaCreator.ConstructRichPointSet(list2);
			AreaCreator.DeleteSingleEdgePoint(ref list3);
			if (list3.Count == 0)
			{
				return list;
			}
			list3.Sort(new RichPointComparer());
			List<CurveInformationBean> collection = AreaCreator.SearchLongestPathBean(list3);
			list.AddRange(collection);
			return list;
		}

		private List<Curve> GetRoomWallInstanceCurves(List<Curve> roomCurves, List<List<Curve>> instanceCurves)
		{
			List<Curve> list = new List<Curve>();
			foreach (List<Curve> list2 in instanceCurves)
			{
				if (this.IsIntersect(roomCurves, list2))
				{
					list.AddRange(list2);
				}
			}
			return list;
		}

		private List<int> GetWallIds(Room room)
		{
			List<int> list = new List<int>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
			foreach (IList<BoundarySegment> list2 in boundarySegments)
			{
				foreach (BoundarySegment segment in list2)
				{
					Wall wall = segment.GetElement(this.m_doc) as Wall;
					if (wall != null && !list.Contains(wall.Id.IntegerValue))
					{
						list.Add(wall.Id.IntegerValue);
					}
				}
			}
			return list;
		}

		public static List<Curve> GetWallCurves(Room room, Document curDoc)
		{
			Document document = room.Document;
			Transaction transaction = new Transaction(document, "SurfaceLayerWal");
			bool flag = Common.ExistSurfaceLayerWall(room, document);
			if (flag)
			{
				transaction.Start();
				List<ElementId> list = Common.FilterSurfaceLayerWalls(document);
				document.Delete(list);
				document.Regenerate();
			}
			List<Curve> list2 = new List<Curve>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions
			{
                SpatialElementBoundaryLocation = (SpatialElementBoundaryLocation)1
			});
			foreach (IList<BoundarySegment> list3 in boundarySegments)
			{
				IEnumerator<BoundarySegment> enumerator2 = list3.GetEnumerator();
				{
					while (enumerator2.MoveNext())
					{
						BoundarySegment segment = enumerator2.Current;
						if (segment.GetElement(curDoc) != null)
						{
							Type type = segment.GetElement(curDoc).GetType();
							ModelCurve modelCurve = segment.GetElement(curDoc) as ModelCurve;
							if ((typeof(Wall) == type || modelCurve != null) && segment.GetCurve().Length > AssistFunc.mmToFeet(5.0))
							{
								list2.Add(segment.GetCurve());
							}
						}
					}
					break;
				}
			}
			if (flag)
			{
				transaction.RollBack();
			}
			return list2;
		}

		private List<Curve> GetInnerWallCurves(Room room)
		{
			bool flag = Common.ExistSurfaceLayerWall(room, this.m_doc);
			if (flag)
			{
				Document document = room.Document;
				List<ElementId> list = Common.FilterSurfaceLayerWalls(document);
				document.Delete(list);
				document.Regenerate();
			}
			List<Curve> list2 = new List<Curve>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions
			{
                SpatialElementBoundaryLocation = (SpatialElementBoundaryLocation)1
			});
			foreach (IList<BoundarySegment> list3 in boundarySegments)
			{
				IEnumerator<BoundarySegment> enumerator2 = list3.GetEnumerator();
				{
					while (enumerator2.MoveNext())
					{
						BoundarySegment segment = enumerator2.Current;
						if (segment.GetElement(this.m_doc) != null)
						{
							Type type = segment.GetElement(this.m_doc).GetType();
							ModelCurve modelCurve = segment.GetElement(this.m_doc) as ModelCurve;
							if ((typeof(Wall) == type || modelCurve != null) && segment.GetCurve().Length > AssistFunc.mmToFeet(0.8))
							{
								list2.Add(segment.GetCurve());
							}
						}
					}
					break;
				}
			}
			return list2;
		}

		private List<CurveInformationBean> GetInnerWallCurveBeans(Room room)
		{
			bool flag = Common.ExistSurfaceLayerWall(room, this.m_doc);
			if (flag)
			{
				Document document = room.Document;
				List<ElementId> list = Common.FilterSurfaceLayerWalls(document);
				document.Delete(list);
				document.Regenerate();
			}
			List<CurveInformationBean> list2 = new List<CurveInformationBean>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions
			{
                SpatialElementBoundaryLocation = (SpatialElementBoundaryLocation)1
			});
			ElementId elementId = null;
			foreach (IList<BoundarySegment> list3 in boundarySegments)
			{
				IEnumerator<BoundarySegment> enumerator2 = list3.GetEnumerator();
				{
					while (enumerator2.MoveNext())
					{
						BoundarySegment boundarySegment = enumerator2.Current;
						elementId = null;
						Element element = null;
						RevitLinkInstance revitLinkInstance = null;
						ElementId boundarySegmentElementId = RevitElementExtension.GetBoundarySegmentElementId(boundarySegment, out elementId);
						if (null != boundarySegmentElementId)
						{
							element = this.m_doc.GetElement(boundarySegmentElementId);
						}
						if (null != elementId && element is RevitLinkInstance)
						{
							revitLinkInstance = (element as RevitLinkInstance);
							element = revitLinkInstance.GetLinkDocument().GetElement(elementId);
						}
						if (element != null)
						{
							Type type = element.GetType();
							ModelCurve modelCurve = element as ModelCurve;
							if ((typeof(Wall) == type || modelCurve != null) && boundarySegment.GetCurve().Length > AssistFunc.mmToFeet(5.0))
							{
								list2.Add(new CurveInformationBean(boundarySegment.GetCurve(), element, revitLinkInstance));
							}
						}
					}
					break;
				}
			}
			return list2;
		}

		private Dictionary<int, List<List<Curve>>> GetWallInstanceCurve(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			Dictionary<int, List<List<Curve>>> dictionary = new Dictionary<int, List<List<Curve>>>();
			this.GetRoomWalls(doc, rooms);
			new List<Curve>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(FamilyInstance));
			foreach (Element element in filteredElementCollector)
			{
                BuiltInCategory integerValue = (BuiltInCategory)element.Category.Id.IntegerValue;
				FamilyInstance familyInstance = element as FamilyInstance;
				if (familyInstance != null && (-2000023 == (int)integerValue || -2000014 == (int)integerValue || (-2000151 == (int)integerValue && familyInstance.Symbol.Family.Name.Contains("洞口"))))
				{
					int integerValue2 = familyInstance.Host.Id.IntegerValue;
					Wall wall = doc.GetElement(new ElementId(integerValue2)) as Wall;
					if (wall == null)
					{
						continue;
					}
					List<Curve> item = this.ConstructInstanceBoundary(familyInstance, wall);
					if (dictionary.ContainsKey(integerValue2))
					{
						dictionary[integerValue2].Add(item);
					}
					else
					{
						dictionary.Add(integerValue2, new List<List<Curve>>
						{
							item
						});
					}
				}
				Opening opening = element as Opening;
				if (opening != null)
				{
					int integerValue3 = opening.Host.Id.IntegerValue;
					Wall wall2 = doc.GetElement(new ElementId(integerValue3)) as Wall;
					if (wall2 != null)
					{
						List<Curve> list = this.ConstructOpeningBoundary(opening, wall2);
						if (list != null)
						{
							if (dictionary.ContainsKey(integerValue3))
							{
								dictionary[integerValue3].Add(list);
							}
							else
							{
								dictionary.Add(integerValue3, new List<List<Curve>>
								{
									list
								});
							}
						}
					}
				}
			}
			return dictionary;
		}

		private List<Curve> GetIntersectColumnCurves(List<List<Curve>> allColumnCurves, List<Curve> roomWallSideCurves)
		{
			List<Curve> list = new List<Curve>();
			foreach (List<Curve> list2 in allColumnCurves)
			{
				if (this.IsIntersect(list2, roomWallSideCurves))
				{
					list.AddRange(list2);
				}
			}
			return list;
		}

		private bool IsIntersect(List<Curve> eachColumnCurves, List<Curve> roomWallSideCurves)
		{
			foreach (Curve curve in eachColumnCurves)
			{
				foreach (Curve curve2 in roomWallSideCurves)
				{
                    if ((SetComparisonResult)8 == curve.Intersect(curve2))
					{
						return true;
					}
				}
			}
			return false;
		}

		private List<List<Curve>> GetColumnCurves(Autodesk.Revit.DB.Document doc)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ICollection<Element> collection = filteredElementCollector.OfClass(typeof(FamilyInstance)).ToElements();
			foreach (Element element in collection)
			{
				int integerValue = element.Category.Id.IntegerValue;
				if (-2001330 == (int)integerValue || -2000100 == (int)integerValue)
				{
					List<Curve> columnEdges = this.GetColumnEdges(element as FamilyInstance);
					list.Add(columnEdges);
				}
			}
			return list;
		}

		private List<Curve> GetColumnEdges(FamilyInstance column)
		{
			List<Curve> list = new List<Curve>();
			GeometryElement geometryElement = column.get_Geometry(new Options());
			foreach (GeometryObject geometryObject in geometryElement)
			{
                //geometryObject.GetType() == typeof(Solid);
				if (geometryObject is Solid)
				{
					Solid solid = geometryObject as Solid;
					FaceArray faces = solid.Faces;
					foreach (object obj in faces)
					{
						Face face = (Face)obj;
						if (!(face.GetType() != typeof(PlanarFace)))
						{
							PlanarFace planarFace = face as PlanarFace;
							if (planarFace.FaceNormal().IsAlmostEqualTo(XYZ.BasisZ))
							{
								EdgeArrayArray edgeLoops = planarFace.EdgeLoops;
								foreach (object obj2 in edgeLoops)
								{
									EdgeArray edgeArray = (EdgeArray)obj2;
									foreach (object obj3 in edgeArray)
									{
										Edge edge = (Edge)obj3;
										Curve curve = edge.AsCurve();
										list.Add(this.GetXYPlaneCurve(curve));
									}
								}
							}
						}
					}
				}
			}
			return list;
		}

		private Curve GetXYPlaneCurve(Curve curve)
		{
			XYZ endPoint = curve.GetEndPoint(0);
			XYZ endPoint2 = curve.GetEndPoint(1);
			if (curve.GetType() == typeof(Line))
			{
				XYZ xyz = new XYZ(endPoint.X, endPoint.Y, 0.0);
				XYZ xyz2 = new XYZ(endPoint2.X, endPoint2.Y, 0.0);
				return Line.CreateBound(xyz, xyz2);
			}
			if (curve.GetType() == typeof(Arc))
			{
				Arc arc = curve as Arc;
				double num = arc.ComputeRawParameter(0.0);
				double num2 = arc.ComputeRawParameter(1.0);
				XYZ xyz3 = new XYZ(arc.Center.X, arc.Center.Y, 0.0);
				return Arc.Create(xyz3, arc.Radius, num, num2, arc.XDirection, arc.YDirection);
			}
			return null;
		}

		private List<Curve> GetComponentCurvesInRoom(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			List<Wall> roomWalls = this.GetRoomWalls(doc, rooms);
			List<Curve> list = new List<Curve>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(FamilyInstance));
			foreach (Element element in filteredElementCollector)
			{
                BuiltInCategory integerValue = (BuiltInCategory)element.Category.Id.IntegerValue;
				FamilyInstance instance = element as FamilyInstance;
				if (instance != null && (-2000023 == (int)integerValue || -2000014 == (int)integerValue || (-2000151 == (int)integerValue && instance.Symbol.Family.Name.Contains("洞口"))))
				{
					Wall wall = roomWalls.Find((Wall a) => a.Id == instance.Host.Id);
					if (wall != null)
					{
						list.AddRange(this.ConstructInstanceBoundary(instance, wall));
					}
				}
				Opening opening = element as Opening;
				if (opening != null)
				{
					Wall wall2 = roomWalls.Find((Wall a) => a.Id == opening.Host.Id);
					if (wall2 != null)
					{
						List<Curve> list2 = this.ConstructOpeningBoundary(opening, wall2);
						if (list2 != null)
						{
							list.AddRange(list2);
						}
					}
				}
			}
			return list;
		}

		private List<Curve> ConstructOpeningBoundary(Opening opening, Wall wall)
		{
			if (opening.IsRectBoundary)
			{
				IList<XYZ> boundaryRect = opening.BoundaryRect;
				double width = wall.Width;
				XYZ xyz = wall.Orientation.Normalize();
				XYZ xyz2 = new XYZ(boundaryRect[0].X, boundaryRect[0].Y, 0.0);
				XYZ xyz3 = new XYZ(boundaryRect[1].X, boundaryRect[1].Y, 0.0);
				XYZ xyz4 = xyz2 + xyz * width / 2.0;
				XYZ xyz5 = xyz2 - xyz * width / 2.0;
				XYZ xyz6 = xyz3 - xyz * width / 2.0;
				XYZ xyz7 = xyz3 + xyz * width / 2.0;
				return new List<Curve>
				{
					Line.CreateBound(xyz4, xyz5),
					Line.CreateBound(xyz5, xyz6),
					Line.CreateBound(xyz6, xyz7),
					Line.CreateBound(xyz7, xyz4)
				};
			}
			return null;
		}

		private List<Curve> ConstructInstanceBoundary(FamilyInstance instance, Wall wall)
		{
			Parameter parameter = instance.Symbol.get_Parameter(BuiltInParameter.CASEWORK_WIDTH);
			double num = parameter.AsDouble();
			double width = wall.Width;
			LocationPoint locationPoint = instance.Location as LocationPoint;
			XYZ xyz = instance.HandOrientation.Normalize();
			XYZ xyz2 = instance.FacingOrientation.Normalize();
			XYZ xyz3 = new XYZ(locationPoint.Point.X, locationPoint.Point.Y, 0.0);
			XYZ xyz4 = xyz3 + xyz * num / 2.0 + xyz2 * width / 2.0;
			XYZ xyz5 = xyz3 + xyz * num / 2.0 - xyz2 * width / 2.0;
			XYZ xyz6 = xyz3 - xyz * num / 2.0 - xyz2 * width / 2.0;
			XYZ xyz7 = xyz3 - xyz * num / 2.0 + xyz2 * width / 2.0;
			return new List<Curve>
			{
				Line.CreateBound(xyz4, xyz5),
				Line.CreateBound(xyz5, xyz6),
				Line.CreateBound(xyz6, xyz7),
				Line.CreateBound(xyz7, xyz4)
			};
		}

		private List<Wall> GetRoomWalls(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			List<Wall> list = new List<Wall>();
			foreach (Room room in rooms)
			{
				new List<Curve>();
				IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
				foreach (IList<BoundarySegment> list2 in boundarySegments)
				{
					foreach (BoundarySegment segment in list2)
					{
						Wall wall = segment.GetElement(doc) as Wall;
						if (wall != null)
						{
							list.Add(wall);
						}
					}
				}
			}
			return list;
		}

		private List<Curve> GetRoomWallSideCurves(Room room)
		{
			List<Curve> list = new List<Curve>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
			foreach (IList<BoundarySegment> list2 in boundarySegments)
			{
				foreach (BoundarySegment segment in list2)
				{
					Wall wall = segment.GetElement(this.m_doc) as Wall;
					if (wall != null)
					{
						Curve wallSideCurves = this.GetWallSideCurves(wall, segment.GetCurve());
						list.Add(wallSideCurves);
					}
				}
			}
			return list;
		}

		private Curve GetWallSideCurves(Wall wall, Curve innerCurve)
		{
			LocationCurve locationCurve = wall.Location as LocationCurve;
			Curve curve = locationCurve.Curve;
			double width = wall.Width;
			XYZ xyz = wall.Orientation.Normalize();
			new List<Curve>();
			if (curve.GetType() == typeof(Line))
			{
				Line line = curve as Line;
				XYZ endPoint = line.GetEndPoint(0);
				XYZ endPoint2 = line.GetEndPoint(1);
				XYZ xyz2 = endPoint + xyz * width / 2.0;
				XYZ xyz3 = endPoint2 + xyz * width / 2.0;
				XYZ xyz4 = endPoint - xyz * width / 2.0;
				XYZ xyz5 = endPoint2 - xyz * width / 2.0;
				Line line2 = Line.CreateBound(xyz2, xyz3);
				Line line3 = Line.CreateBound(xyz4, xyz5);
                if ((SetComparisonResult)64 != line2.Intersect(innerCurve))
				{
					return line2;
				}
                if ((SetComparisonResult)64 != line3.Intersect(innerCurve))
				{
					return line3;
				}
			}
			else if (curve.GetType() == typeof(Arc))
			{
				Arc arc = curve as Arc;
				double num = arc.ComputeRawParameter(0.0);
				double num2 = arc.ComputeRawParameter(1.0);
				Arc arc2 = Arc.Create(arc.Center, arc.Radius + width / 2.0, num, num2, arc.XDirection, arc.YDirection);
				Arc arc3 = Arc.Create(arc.Center, arc.Radius - width / 2.0, num, num2, arc.XDirection, arc.YDirection);
                if ((SetComparisonResult)64 != arc2.Intersect(innerCurve))
				{
					return arc2;
				}
                if ((SetComparisonResult)64 != arc3.Intersect(innerCurve))
				{
					return arc3;
				}
			}
			return null;
		}

		private List<List<CurveInformationBean>> GetLargestClosedAreas(List<CurveInformationBean> curves)
		{
			List<CurveInformationBean> list = AreaCreator.BreakCurves(curves);
			AreaCreator.RemoveRepeatCurves(list);
			List<RichPoint> list2 = AreaCreator.ConstructRichPointSet(list);
			AreaCreator.DeleteSingleEdgePoint(ref list2);
			list2.Sort(new RichPointComparer());
			return this.GetLongestPathBeanAreas(list2);
		}

		private List<List<CurveInformationBean>> GetLongestPathBeanAreas(List<RichPoint> richPoints)
		{
			List<List<CurveInformationBean>> list = new List<List<CurveInformationBean>>();
			while (richPoints.Count > 1)
			{
				List<CurveInformationBean> list2 = AreaCreator.SearchLongestPathBean(richPoints);
				list.Add(list2);
				List<XYZ> list3 = new List<XYZ>();
				foreach (CurveInformationBean curveInformationBean in list2)
				{
					list3.AddRange(curveInformationBean.ThisCurve.Tessellate());
				}
				for (int i = 0; i < richPoints.Count; i++)
				{
					if (-1 != Geometry.PointInPloygon(list3, richPoints[i].m_point, 0.0001, 0.0001))
					{
						richPoints.RemoveAt(i);
						i--;
					}
				}
			}
			return list;
		}

		public static List<CurveInformationBean> GetRoomCurveBeansWithoutInstance(Autodesk.Revit.DB.Document doc, List<Room> rooms)
		{
			List<CurveInformationBean> list = new List<CurveInformationBean>();
			foreach (Room room in rooms)
			{
				List<CurveInformationBean> wallCurveBeans = AreaCreator.GetWallCurveBeans(room, doc);
				List<CurveInformationBean> closedAreaCurves = AreaCreator.GetClosedAreaCurves(wallCurveBeans);
				List<CurveInformationBean> list2 = AreaCreator.BreakCurves(closedAreaCurves);
				AreaCreator.RemoveRepeatCurves(list2);
				List<RichPoint> list3 = AreaCreator.ConstructRichPointSet(list2);
				AreaCreator.DeleteSingleEdgePoint(ref list3);
				list3.Sort(new RichPointComparer());
				List<CurveInformationBean> collection = AreaCreator.SearchLongestPathBean(list3);
				list.AddRange(collection);
			}
			return list;
		}

		public static List<CurveInformationBean> SplitCurves(CurveInformationBean curve, XYZ ptIntersect)
		{
			XYZ endPoint = curve.ThisCurve.GetEndPoint(0);
			XYZ endPoint2 = curve.ThisCurve.GetEndPoint(1);
			if (ptIntersect.IsAlmostEqualTo(endPoint) || ptIntersect.IsAlmostEqualTo(endPoint2))
			{
				return null;
			}
			List<CurveInformationBean> list = new List<CurveInformationBean>();
			if (curve.ThisCurve.GetType() == typeof(Line))
			{
				if (ptIntersect.DistanceTo(endPoint) > AssistFunc.mmToFeet(0.8))
				{
					list.Add(new CurveInformationBean(Line.CreateBound(endPoint, ptIntersect), curve.ThisElement, curve.ThisRevitLinkInstance));
				}
				if (ptIntersect.DistanceTo(endPoint2) > AssistFunc.mmToFeet(0.8))
				{
					list.Add(new CurveInformationBean(Line.CreateBound(ptIntersect, endPoint2), curve.ThisElement, curve.ThisRevitLinkInstance));
				}
			}
			else if (curve.ThisCurve.GetType() == typeof(Arc))
			{
				Arc arc = curve.ThisCurve as Arc;
				XYZ center = arc.Center;
				XYZ normal = arc.Normal;
				XYZ xyz = Geometry.CalculatMidPoint(endPoint, ptIntersect, center, normal);
				XYZ xyz2 = Geometry.CalculatMidPoint(ptIntersect, endPoint2, center, normal);
				if (ptIntersect.DistanceTo(endPoint) > AssistFunc.mmToFeet(0.8))
				{
					Arc inputCurve = Arc.Create(endPoint, ptIntersect, xyz);
					list.Add(new CurveInformationBean(inputCurve, curve.ThisElement, curve.ThisRevitLinkInstance));
				}
				if (ptIntersect.DistanceTo(endPoint2) > AssistFunc.mmToFeet(0.8))
				{
					Arc inputCurve2 = Arc.Create(ptIntersect, endPoint2, xyz2);
					list.Add(new CurveInformationBean(inputCurve2, curve.ThisElement, curve.ThisRevitLinkInstance));
				}
			}
			return list;
		}

		public static List<CurveInformationBean> BreakCurves(List<CurveInformationBean> curves)
		{
			for (int i = 0; i < curves.Count; i++)
			{
				for (int j = i + 1; j < curves.Count; j++)
				{
					IntersectionResultArray intersectionResultArray;
					SetComparisonResult setComparisonResult = curves[i].ThisCurve.Intersect(curves[j].ThisCurve, out intersectionResultArray);
					if ((SetComparisonResult)8 == setComparisonResult)
					{
						XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
						List<CurveInformationBean> list = AreaCreator.SplitCurves(curves[j], xyzpoint);
						if (list == null && 2 == intersectionResultArray.Size)
						{
							list = AreaCreator.SplitCurves(curves[j], intersectionResultArray.get_Item(1).XYZPoint);
						}
						if (list != null && list.Count > 0)
						{
							curves.RemoveAt(j);
							curves.AddRange(list);
							j--;
						}
						List<CurveInformationBean> list2 = AreaCreator.SplitCurves(curves[i], xyzpoint);
						if (list2 == null && 2 == intersectionResultArray.Size)
						{
							list2 = AreaCreator.SplitCurves(curves[i], intersectionResultArray.get_Item(1).XYZPoint);
						}
						if (list2 != null)
						{
							curves.RemoveAt(i);
							curves.AddRange(list2);
							i--;
							break;
						}
					}
				}
			}
			return curves;
		}

		public static void RemoveRepeatCurves(List<CurveInformationBean> curves)
		{
			for (int i = 0; i < curves.Count; i++)
			{
				for (int j = i + 1; j < curves.Count; j++)
				{
					SetComparisonResult setComparisonResult = curves[i].ThisCurve.Intersect(curves[j].ThisCurve);
                    if ((SetComparisonResult)64 == setComparisonResult)
					{
						XYZ endPoint = curves[i].ThisCurve.GetEndPoint(0);
						XYZ endPoint2 = curves[i].ThisCurve.GetEndPoint(1);
						XYZ endPoint3 = curves[j].ThisCurve.GetEndPoint(0);
						XYZ endPoint4 = curves[j].ThisCurve.GetEndPoint(1);
						if (Math.Abs(curves[i].ThisCurve.Length - curves[j].ThisCurve.Length) < 1E-05 && ((endPoint.IsAlmostEqualTo(endPoint3) && endPoint2.IsAlmostEqualTo(endPoint4)) || (endPoint.IsAlmostEqualTo(endPoint4) && endPoint2.IsAlmostEqualTo(endPoint3))))
						{
							curves.RemoveAt(j);
							j--;
						}
					}
				}
			}
		}

		public static List<RichPoint> ConstructRichPointSet(List<CurveInformationBean> splitCurves)
		{
			List<RichPoint> list = new List<RichPoint>();
			foreach (CurveInformationBean curveInformationBean in splitCurves)
			{
				XYZ ptStart = curveInformationBean.ThisCurve.GetEndPoint(0);
				int num = list.FindIndex((RichPoint a) => a.m_point.IsAlmostEqualTo(ptStart));
				if (-1 == num)
				{
					list.Add(new RichPoint(ptStart, curveInformationBean));
				}
				else
				{
					list[num].AddCurve(curveInformationBean);
				}
				XYZ ptEnd = curveInformationBean.ThisCurve.GetEndPoint(1);
				num = list.FindIndex((RichPoint a) => a.m_point.IsAlmostEqualTo(ptEnd));
				if (-1 == num)
				{
					list.Add(new RichPoint(ptEnd, new CurveInformationBean(AreaCreator.CreateReversedCurve(curveInformationBean.ThisCurve), curveInformationBean.ThisElement, curveInformationBean.ThisRevitLinkInstance)));
				}
				else
				{
					list[num].AddCurve(new CurveInformationBean(AreaCreator.CreateReversedCurve(curveInformationBean.ThisCurve), curveInformationBean.ThisElement, curveInformationBean.ThisRevitLinkInstance));
				}
			}
			return list;
		}

		public static List<CurveInformationBean> SearchLongestPathBean(List<RichPoint> richPoints)
		{
			XYZ xyz = XYZ.BasisY.Negate();
			double num = 0.0;
			List<CurveInformationBean> list = new List<CurveInformationBean>();
			if (richPoints.Count == 0)
			{
				return list;
			}
			CurveInformationBean curveInformationBean = null;
			XYZ ptCurrent = richPoints[0].m_point;
			do
			{
				RichPoint richPoint = richPoints.Find((RichPoint a) => a.m_point.IsAlmostEqualTo(ptCurrent));
				if (richPoint.m_curves == null)
				{
					break;
				}
				foreach (CurveInformationBean curveInformationBean2 in richPoint.m_lstCurveInformationBean)
				{
					XYZ tangentAt = AreaCreator.GetTangentAt(curveInformationBean2.ThisCurve);
					double num2 = xyz.AngleOnPlaneTo(tangentAt, XYZ.BasisZ);
					if (Math.Round(Math.PI*2, 4) == Math.Round(num2, 4))
					{
						num2 = 0.0;
					}
					if (num2 > num)
					{
						curveInformationBean = curveInformationBean2;
						num = num2;
					}
				}
				list.Add(curveInformationBean);
				ptCurrent = curveInformationBean.ThisCurve.GetEndPoint(1);
				xyz = AreaCreator.GetTangentAt(AreaCreator.CreateReversedCurve(curveInformationBean.ThisCurve));
				num = 0.0;
			}
			while (!ptCurrent.IsAlmostEqualTo(richPoints[0].m_point));
			return list;
		}

		public static List<CurveInformationBean> GetClosedAreaCurves(List<CurveInformationBean> wallCurves)
		{
			XYZ xyz = XYZ.Zero;
			int i = 0;
			while (i < wallCurves.Count)
			{
				int num = (i + 1) % wallCurves.Count;
				IntersectionResultArray intersectionResultArray;
				SetComparisonResult setComparisonResult = wallCurves[i].ThisCurve.Intersect(wallCurves[num].ThisCurve, out intersectionResultArray);
				if ((SetComparisonResult)8 == setComparisonResult)
				{
					XYZ endPoint = wallCurves[i].ThisCurve.GetEndPoint(0);
					XYZ endPoint2 = wallCurves[i].ThisCurve.GetEndPoint(1);
					XYZ xyzpoint = intersectionResultArray.get_Item(0).XYZPoint;
					if (xyzpoint.DistanceTo(endPoint) <= xyzpoint.DistanceTo(endPoint2))
					{
						if (2 != intersectionResultArray.Size)
						{
							goto IL_E9;
						}
					}
				}
                else if ((SetComparisonResult)64 == setComparisonResult)
				{
					wallCurves.RemoveAt(num);
					i--;
					if (num == 0)
					{
						i--;
					}
				}
				else if (!wallCurves[i].ThisCurve.GetEndPoint(1).IsAlmostEqualTo(wallCurves[num].ThisCurve.GetEndPoint(0)))
				{
					goto IL_E9;
				}
				IL_26B:
				i++;
				continue;
				IL_E9:
				Curve curve = wallCurves[i].ThisCurve.Clone();
				curve.MakeUnbound();
				Curve curve2 = wallCurves[num].ThisCurve.Clone();
				curve2.MakeUnbound();
				setComparisonResult = curve.Intersect(curve2, out intersectionResultArray);
                if ((SetComparisonResult)4 == setComparisonResult || (SetComparisonResult)64 == setComparisonResult)
				{
					Curve inputCurve = null;
					bool shortestCurve = AreaCreator.GetShortestCurve(wallCurves[i].ThisCurve, wallCurves[num].ThisCurve, ref inputCurve);
					if (shortestCurve)
					{
						wallCurves.Insert(num, new CurveInformationBean(inputCurve, null, null));
						i++;
						goto IL_26B;
					}
					wallCurves.RemoveAt(i);
					wallCurves.Insert(i, new CurveInformationBean(inputCurve, null, null));
					goto IL_26B;
				}
				else
				{
					if ((SetComparisonResult)8 == setComparisonResult)
					{
						xyz = intersectionResultArray.get_Item(0).XYZPoint;
						XYZ endPoint3 = wallCurves[i].ThisCurve.GetEndPoint(1);
						if (2 == intersectionResultArray.Size)
						{
							XYZ xyzpoint2 = intersectionResultArray.get_Item(1).XYZPoint;
							if (xyz.DistanceTo(endPoint3) > xyzpoint2.DistanceTo(endPoint3))
							{
								xyz = xyzpoint2;
							}
						}
						Curve inputCurve2 = AreaCreator.ExtendCurve(wallCurves[i].ThisCurve, xyz);
						CurveInformationBean curveInformationBean = wallCurves[i];
						wallCurves.RemoveAt(i);
						wallCurves.Insert(i, new CurveInformationBean(inputCurve2, curveInformationBean.ThisElement, curveInformationBean.ThisRevitLinkInstance));
						Curve inputCurve3 = AreaCreator.ExtendCurve(wallCurves[num].ThisCurve, xyz);
						curveInformationBean = wallCurves[num];
						wallCurves.RemoveAt(num);
						wallCurves.Insert(num, new CurveInformationBean(inputCurve3, curveInformationBean.ThisElement, curveInformationBean.ThisRevitLinkInstance));
						goto IL_26B;
					}
					goto IL_26B;
				}
			}
			return wallCurves;
		}

		public static List<CurveInformationBean> GetWallCurveBeans(Room room, Document curDoc)
		{
			Document document = room.Document;
			Transaction transaction = new Transaction(document, "SurfaceLayerWal");
			bool flag = Common.ExistSurfaceLayerWall(room, document);
			if (flag)
			{
				transaction.Start();
				List<ElementId> list = Common.FilterSurfaceLayerWalls(document);
				document.Delete(list);
				document.Regenerate();
			}
			List<CurveInformationBean> list2 = new List<CurveInformationBean>();
			IList<IList<BoundarySegment>> boundarySegments = room.GetBoundarySegments(new SpatialElementBoundaryOptions
			{
                SpatialElementBoundaryLocation = (SpatialElementBoundaryLocation)1
			});
			ElementId elementId = null;
			foreach (IList<BoundarySegment> list3 in boundarySegments)
			{
				IEnumerator<BoundarySegment> enumerator2 = list3.GetEnumerator();
				{
					while (enumerator2.MoveNext())
					{
						BoundarySegment boundarySegment = enumerator2.Current;
						elementId = null;
						Element element = null;
						RevitLinkInstance revitLinkInstance = null;
						ElementId boundarySegmentElementId = RevitElementExtension.GetBoundarySegmentElementId(boundarySegment, out elementId);
						if (null != boundarySegmentElementId)
						{
							element = curDoc.GetElement(boundarySegmentElementId);
						}
						if (null != elementId && element is RevitLinkInstance)
						{
							revitLinkInstance = (element as RevitLinkInstance);
							element = revitLinkInstance.GetLinkDocument().GetElement(elementId);
						}
						else
						{
							element = boundarySegment.GetElement(curDoc);
						}
						if (element != null)
						{
							Type type = element.GetType();
							ModelCurve modelCurve = element as ModelCurve;
							if ((typeof(Wall) == type || modelCurve != null) && boundarySegment.GetCurve().Length > AssistFunc.mmToFeet(5.0))
							{
								list2.Add(new CurveInformationBean(boundarySegment.GetCurve(), element, revitLinkInstance));
							}
						}
					}
					break;
				}
			}
			if (flag)
			{
				transaction.RollBack();
			}
			return list2;
		}

		public static bool AdjustCurvesWithErrorInfo(ref List<CurveInformationBean> curves, Document doc)
		{
			List<XYZ> list = new List<XYZ>();
			if (!AreaCreator.AdjustCurves(ref curves, ref list, doc))
			{
				return false;
			}
			if (list.Count > 0)
			{
				string str = list.Count.ToString();
				if (MessageBox.Show("中心线错位小于0.8mm的墙体有" + str + "个，是否处理完再执行(提示线需要自己删除)？", "盈建科提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					AreaCreator.CreateCurvesForErrorPos(list, doc);
					return false;
				}
			}
			return true;
		}

		public static bool AdjustCurves(ref List<CurveInformationBean> curves, ref List<XYZ> lstPtMiniDist, Document doc)
		{
			lstPtMiniDist = new List<XYZ>();
			List<XYZ> list = new List<XYZ>();
			int i = 0;
			while (i < curves.Count)
			{
				Curve thisCurve = curves[i].ThisCurve;
				XYZ endPoint = thisCurve.GetEndPoint(0);
				XYZ xyz = AreaCreator.FindApproximatePoint(list, endPoint);
				if (xyz != null)
				{
					try
					{
						Curve inputCurve = AreaCreator.ModifyStartPoint(thisCurve, xyz);
						Element thisElement = curves[i].ThisElement;
						RevitLinkInstance thisRevitLinkInstance = curves[i].ThisRevitLinkInstance;
						curves.RemoveAt(i);
						curves.Insert(i, new CurveInformationBean(inputCurve, thisElement, thisRevitLinkInstance));
						if (AreaCreator.Is2PointDistLessThan08(xyz, endPoint))
						{
							lstPtMiniDist.Add(xyz);
						}
						goto IL_A4;
					}
					catch
					{
						goto IL_A4;
					}
					goto IL_9C;
				}
				goto IL_9C;
				IL_A4:
				i++;
				continue;
				IL_9C:
				list.Add(endPoint);
				goto IL_A4;
			}
			int j = 0;
			while (j < curves.Count)
			{
				Curve thisCurve2 = curves[j].ThisCurve;
				XYZ endPoint2 = thisCurve2.GetEndPoint(1);
				XYZ xyz2 = AreaCreator.FindApproximatePoint(list, endPoint2);
				if (xyz2 != null)
				{
					try
					{
						Curve inputCurve2 = AreaCreator.ModifyEndPoint(thisCurve2, xyz2);
						Element thisElement = curves[j].ThisElement;
						RevitLinkInstance thisRevitLinkInstance = curves[j].ThisRevitLinkInstance;
						curves.RemoveAt(j);
						curves.Insert(j, new CurveInformationBean(inputCurve2, thisElement, thisRevitLinkInstance));
						if (AreaCreator.Is2PointDistLessThan08(xyz2, endPoint2))
						{
							lstPtMiniDist.Add(xyz2);
						}
						goto IL_14E;
					}
					catch
					{
						goto IL_14E;
					}
					goto IL_146;
				}
				goto IL_146;
				IL_14E:
				j++;
				continue;
				IL_146:
				list.Add(endPoint2);
				goto IL_14E;
			}
			for (int k = 0; k < lstPtMiniDist.Count - 1; k++)
			{
				XYZ xyz3 = lstPtMiniDist[k];
				for (int l = k + 1; l < lstPtMiniDist.Count; l++)
				{
					XYZ xyz4 = lstPtMiniDist[l];
					if (xyz3.DistanceTo(xyz4) < AssistFunc.mmToFeet(0.8))
					{
						lstPtMiniDist.RemoveAt(l);
						l--;
					}
				}
			}
			return true;
		}

		public static void CreateCurvesForErrorPos(XYZ pt, Document doc)
		{
			double num = (double)YJKRevitTools.GetViewPlanScale(doc) / 100.0;
			List<Curve> list = new List<Curve>();
			double num2 = 500.0;
			num2 = AssistFunc.mmToFeet(num2) * num;
			double num3 = Math.Sqrt(num2 * num2 * 2.0) / 2.0;
			double num4 = num2 / 500.0;
			XYZ xyz = new XYZ(num3, num3, 0.0);
			XYZ xyz2 = new XYZ(num3, -num3, 0.0);
			list.Add(Line.CreateBound(pt + xyz, pt - xyz));
			list.Add(Line.CreateBound(pt + xyz2, pt - xyz2));
			list.Add(Arc.Create(pt, num4, 0.0, Math.PI*2, XYZ.BasisX, XYZ.BasisY));
			list.Add(Arc.Create(pt, num2, 0.0, Math.PI*2, XYZ.BasisX, XYZ.BasisY));
			foreach (Curve curve in list)
			{
				try
				{
					DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, curve);
					string text = "墙体错位红色线";
					Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
					Category category2;
					if (category.SubCategories.Contains(text))
					{
						category2 = category.SubCategories.get_Item(text);
					}
					else
					{
						category2 = doc.Settings.Categories.NewSubcategory(category, text);
					}
                    category2.LineColor = new Autodesk.Revit.DB.Color(byte.MaxValue, 0, 0);
					category2.SetLineWeight(8, (Autodesk.Revit.DB.GraphicsStyleType)1);
                    GraphicsStyle graphicsStyle = category2.GetGraphicsStyle((Autodesk.Revit.DB.GraphicsStyleType)1);
					if (graphicsStyle != null)
					{
						detailCurve.LineStyle = graphicsStyle;
					}
				}
				catch (Exception ex)
				{
					YJKMessageBox.Show(ex.Message);
				}
			}
		}

		public bool MergeFireZoneByBoundCurve(Autodesk.Revit.DB.Document doc, KeyValuePair<FireZoneInfo, List<Area>> itemGroupArea)
		{
			List<Area> value = itemGroupArea.Value;
			if (value.Count == 0)
			{
				return true;
			}
			AreaTagType areaTag = null;
			AreaTagType areaCharacterType = null;
			this.GetAreaTag(value[0], out areaTag, out areaCharacterType);
			OverrideGraphicSettings settings = new OverrideGraphicSettings();
			this.GetAreaSetting(value, ref settings);
			List<Curve> list = new List<Curve>();
			List<List<Curve>> list2 = new List<List<Curve>>();
			foreach (Area area in value)
			{
				ClosedArea fireZoneBoundaryCurves = this.GetFireZoneBoundaryCurves(area);
				list.AddRange(fireZoneBoundaryCurves.m_outerBoundary);
				foreach (List<Curve> collection in fireZoneBoundaryCurves.m_innerBoundary)
				{
					List<Curve> list3 = new List<Curve>();
					list3.AddRange(collection);
					this.ManageMiniCurves(ref list3, doc);
					list2.Add(list3);
				}
			}
			this.ManageMiniCurves(ref list, doc);
			List<List<Curve>> largestClosedAreas = this.GetLargestClosedAreas(list);
			List<List<Curve>> list4 = new List<List<Curve>>();
			list4.Add(list);
			List<ClosedArea> allAreas = this.GetAllAreas(largestClosedAreas, list2);
			Transaction transaction = new Transaction(doc, "Merge FireZone By Curves");
			transaction.Start();
			try
			{
				this.DeleteAreaInfo(value);
				foreach (ClosedArea closedArea in allAreas)
				{
					if (ElementId.InvalidElementId != closedArea.m_areaId)
					{
						this.CreateFireZone(doc, closedArea, itemGroupArea.Key, areaTag, areaCharacterType, settings, false);
					}
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
				return false;
			}
			return true;
		}

		private bool ManageMiniCurves(ref List<Curve> lstZoneCurves, Document doc)
		{
			for (int i = 0; i < lstZoneCurves.Count; i++)
			{
				Curve curve = lstZoneCurves[i];
				double num = curve.GetEndPoint(0).DistanceTo(curve.GetEndPoint(1));
				if (AssistFunc.mmToFeet(0.8) > num)
				{
					lstZoneCurves.RemoveAt(i);
					i--;
				}
			}
			List<XYZ> list = new List<XYZ>();
			return AreaCreator.AdjustCurves(ref lstZoneCurves, ref list, doc);
		}

		private bool GetAreaSetting(List<Area> lstArea, ref OverrideGraphicSettings curSetting)
		{
			new List<ElementId>();
			foreach (Area element in lstArea)
			{
				IList<ElementId> list = Common.ReadAreaData(element);
				if (list != null && list.Count > 0)
				{
					Element element2 = this.m_doc.GetElement(list[0]);
					if (element2 is ModelCurve)
					{
						curSetting = this.m_doc.ActiveView.GetElementOverrides(list[0]);
						return true;
					}
				}
			}
			return false;
		}

		private bool DeleteAreaInfo(List<Area> lstArea)
		{
			try
			{
				List<ElementId> list = new List<ElementId>();
				foreach (Area area in lstArea)
				{
					IList<ElementId> collection = Common.ReadAreaData(area);
					list.AddRange(collection);
					this.m_doc.Delete(area.Id);
				}
				foreach (ElementId elementId in list)
				{
					ModelCurve modelCurve = this.m_doc.GetElement(elementId) as ModelCurve;
					if (modelCurve != null)
					{
						this.m_doc.Delete(elementId);
					}
				}
				this.m_doc.Regenerate();
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		public bool MergeFireZoneByBoundCurveBackup(Autodesk.Revit.DB.Document doc, KeyValuePair<FireZoneInfo, List<Area>> GroupArea)
		{
			List<Area> value = GroupArea.Value;
			AreaTagType areaTag = null;
			AreaTagType areaCharacterType = null;
			this.GetAreaTag(value[0], out areaTag, out areaCharacterType);
			List<Curve> curves = new List<Curve>();
			OverrideGraphicSettings settings = new OverrideGraphicSettings();
			this.GetAreaSettingAndCurve(value, ref settings, ref curves);
			if (!AreaCreator.AdjustCurvesWithErrorInfo(ref curves, doc))
			{
				return false;
			}
			List<List<Curve>> largestClosedAreas = this.GetLargestClosedAreas(curves);
			List<List<Curve>> innerAreas = this.GetInnerAreas(doc);
			List<ClosedArea> allAreas = this.GetAllAreas(largestClosedAreas, innerAreas);
			List<ClosedArea> fireZoneBoundary = this.GetFireZoneBoundary(doc);
			List<ClosedArea> list = this.RegroupAreas(allAreas, fireZoneBoundary);
			Transaction transaction = new Transaction(doc, "Create FireZone By Curves");
			transaction.Start();
			try
			{
				foreach (ClosedArea closedArea in allAreas)
				{
					if (ElementId.InvalidElementId != closedArea.m_areaId)
					{
						this.CreateFireZone(doc, closedArea, GroupArea.Key, areaTag, areaCharacterType, settings, false);
					}
				}
				foreach (ClosedArea closedArea2 in list)
				{
					this.CreateFireZone(doc, closedArea2, GroupArea.Key, areaTag, areaCharacterType, settings, true);
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
				return false;
			}
			return true;
		}

		private bool CreateFireZone(Autodesk.Revit.DB.Document doc, ClosedArea closedArea, FireZoneInfo fireZoneInfo, AreaTagType AreaTag, AreaTagType AreaCharacterType, OverrideGraphicSettings Settings, bool bExistArea = false)
		{
			if (bExistArea)
			{
				Area area = Common.CreateArea(doc, closedArea, Settings);
				this.SetFireZoneParameters(doc, area, closedArea.m_fireZoneInfo);
				doc.Regenerate();
				XYZ areaCurveCenterPt = Common.GetAreaCurveCenterPt(closedArea.m_outerBoundary);
				this.SetFireZoneTag(doc, areaCurveCenterPt, area, AreaTag, AreaCharacterType);
			}
			else
			{
				Area area2 = Common.CreateArea(doc, closedArea, Settings);
				this.SetFireZoneParameters(doc, area2, fireZoneInfo);
				doc.Regenerate();
				XYZ areaCurveCenterPt2 = Common.GetAreaCurveCenterPt(closedArea.m_outerBoundary);
				this.SetFireZoneTag(doc, areaCurveCenterPt2, area2, AreaTag, AreaCharacterType);
			}
			return true;
		}

		private void SetFireZoneTag(Autodesk.Revit.DB.Document doc, XYZ ptCenter, Area area, AreaTagType AreaTagT, AreaTagType AreaCharacterT)
		{
			UV uv = new UV(ptCenter.X, ptCenter.Y);
			ViewPlan viewPlan = doc.ActiveView as ViewPlan;
			if (AreaTagT != null && AreaCharacterT == null)
			{
				AreaTag areaTag = doc.Create.NewAreaTag(viewPlan, area, uv);
				areaTag.AreaTagType = AreaTagT;
				areaTag.GetParameter("引线").Set(0);
				return;
			}
			if (AreaTagT == null && AreaCharacterT != null)
			{
				AreaTag areaTag2 = doc.Create.NewAreaTag(viewPlan, area, uv);
				areaTag2.AreaTagType = AreaCharacterT;
				areaTag2.GetParameter("引线").Set(0);
				return;
			}
			if (AreaTagT != null && AreaCharacterT != null)
			{
				AreaTag areaTag3 = doc.Create.NewAreaTag(viewPlan, area, uv);
				areaTag3.AreaTagType = AreaCharacterT;
				areaTag3.GetParameter("引线").Set(0);
				UV uv2 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag4 = doc.Create.NewAreaTag(viewPlan, area, uv2);
				areaTag4.AreaTagType = AreaTagT;
				areaTag4.GetParameter("引线").Set(0);
			}
		}

		private bool GetAreaSettingAndCurve(List<Area> ListArea, ref OverrideGraphicSettings Setting, ref List<Curve> AreaBoundCurves)
		{
			bool flag = false;
			Transaction transaction = new Transaction(this.m_doc, "删除防火分区");
			transaction.Start();
			try
			{
				List<ElementId> list = new List<ElementId>();
				foreach (Area area in ListArea)
				{
					IList<ElementId> list2 = Common.ReadAreaData(area);
					list.AddRange(list2);
					this.m_doc.Delete(area.Id);
					if (!flag)
					{
						Element element = this.m_doc.GetElement(list2[0]);
						if (!(element is ModelCurve))
						{
							transaction.RollBack();
							return false;
						}
						Setting = this.m_doc.ActiveView.GetElementOverrides(list2[0]);
					}
					List<Curve> list3 = new List<Curve>();
					foreach (ElementId elementId in list2)
					{
						ModelCurve modelCurve = this.m_doc.GetElement(elementId) as ModelCurve;
						if (modelCurve == null)
						{
							transaction.RollBack();
							return false;
						}
						list3.Add(modelCurve.GeometryCurve);
					}
					List<Curve> closedAreaCurves = AreaCreator.GetClosedAreaCurves(list3);
					List<Curve> list4 = AreaCreator.BreakCurves(closedAreaCurves);
					AreaCreator.RemoveRepeatCurves(list4);
					List<RichPoint> list5 = AreaCreator.ConstructRichPointSet(list4);
					AreaCreator.DeleteSingleEdgePoint(ref list5);
					if (list5.Count == 0)
					{
						return true;
					}
					list5.Sort(new RichPointComparer());
					List<Curve> collection = AreaCreator.SearchLongestPath(list5);
					AreaBoundCurves.AddRange(collection);
				}
				foreach (ElementId elementId2 in list)
				{
					if (!(this.m_doc.GetElement(elementId2) is ModelCurve))
					{
						transaction.RollBack();
						return false;
					}
					this.m_doc.Delete(elementId2);
				}
				this.m_doc.Regenerate();
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
				return false;
			}
			return true;
		}

		private void GetAreaTag(Area area, out AreaTagType areaType, out AreaTagType areaCharacterType)
		{
			areaType = null;
			areaCharacterType = null;
			List<AreaTag> list = Common.FilterAreaTags(this.m_doc);
			if (list == null)
			{
				return;
			}
			foreach (AreaTag areaTag in list)
			{
				areaTag.Area.GetHashCode();
				area.GetHashCode();
				if (areaTag.Area.Id == area.Id)
				{
					if (areaTag.AreaTagType.Name.Contains("面积"))
					{
						areaType = areaTag.AreaTagType;
					}
					else
					{
						areaCharacterType = areaTag.AreaTagType;
					}
				}
			}
		}

		private Document m_doc;

		private Selection m_sel;

		private ExternalCommandData m_Revit;

		private UIDocument m_uiDoc;

		public enum AreaClip
		{
			Separation,
			Tangent,
			Intersection,
			SuperSet,
			SubSet,
			Equal
		}
	}
}
